mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 03:55:22 +00:00
Merge pull request #30 from hdformat/master
fix for windows, update readme and fix lint warnning
This commit is contained in:
commit
2ffa4d2bf0
12
README.rst
12
README.rst
@ -37,10 +37,14 @@ Usage
|
|||||||
pipreqs [options] <path>
|
pipreqs [options] <path>
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--use-local Use ONLY local package information instead of querying PyPI
|
--use-local Use ONLY local package information instead of querying PyPI
|
||||||
--debug Print debug information
|
--pypi-server Use custom PyPi server
|
||||||
--savepath <file> Save the list of requirements in the given file
|
--proxy Use Proxy, parameter will be passed to requests library
|
||||||
--force Overwrite existing requirements.txt
|
--debug Print debug information
|
||||||
|
--encoding <charset> Use encoding parameter for file open
|
||||||
|
--savepath <file> Save the list of requirements in the given file
|
||||||
|
--force Overwrite existing requirements.txt
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -6,12 +6,13 @@ Usage:
|
|||||||
pipreqs [options] <path>
|
pipreqs [options] <path>
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--use-local Use ONLY local package info instead of querying PyPI
|
--use-local Use ONLY local package info instead of querying PyPI
|
||||||
--pypi-server Use custom PyPi server
|
--pypi-server Use custom PyPi server
|
||||||
--proxy Use Proxy, parameter will be passed to requests library
|
--proxy Use Proxy, parameter will be passed to requests library
|
||||||
--debug Print debug information
|
--debug Print debug information
|
||||||
--savepath <file> Save the list of requirements in the given file
|
--encoding <charset> Use encoding parameter for file open
|
||||||
--force Overwrite existing requirements.txt
|
--savepath <file> Save the list of requirements in the given file
|
||||||
|
--force Overwrite existing requirements.txt
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function, absolute_import
|
from __future__ import print_function, absolute_import
|
||||||
import os
|
import os
|
||||||
@ -32,7 +33,7 @@ REGEXP = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_all_imports(path):
|
def get_all_imports(path, encoding=None):
|
||||||
imports = []
|
imports = []
|
||||||
candidates = []
|
candidates = []
|
||||||
ignore_dirs = [".hg", ".svn", ".git", "__pycache__", "env"]
|
ignore_dirs = [".hg", ".svn", ".git", "__pycache__", "env"]
|
||||||
@ -45,7 +46,7 @@ def get_all_imports(path):
|
|||||||
|
|
||||||
candidates += [os.path.splitext(fn)[0] for fn in files]
|
candidates += [os.path.splitext(fn)[0] for fn in files]
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
with open(os.path.join(root, file_name), "r") as f:
|
with open(os.path.join(root, file_name), "r", encoding=encoding) as f:
|
||||||
lines = filter(
|
lines = filter(
|
||||||
filter_line, map(lambda l: l.partition("#")[0].strip(), f))
|
filter_line, map(lambda l: l.partition("#")[0].strip(), f))
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -94,7 +95,7 @@ def get_imports_info(imports, pypi_server="https://pypi.python.org/pypi/", proxy
|
|||||||
data = json2package(response.content)
|
data = json2package(response.content)
|
||||||
elif response.status_code >= 300:
|
elif response.status_code >= 300:
|
||||||
raise HTTPError(status_code=response.status_code,
|
raise HTTPError(status_code=response.status_code,
|
||||||
reason=response.reason)
|
reason=response.reason)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
'Package %s does not exist or network problems', item)
|
'Package %s does not exist or network problems', item)
|
||||||
@ -111,7 +112,7 @@ def get_locally_installed_packages():
|
|||||||
for item in files:
|
for item in files:
|
||||||
if "top_level" in item:
|
if "top_level" in item:
|
||||||
with open(os.path.join(root, item), "r") as f:
|
with open(os.path.join(root, item), "r") as f:
|
||||||
package = root.split("/")[-1].split("-")
|
package = root.split(os.sep)[-1].split("-")
|
||||||
try:
|
try:
|
||||||
package_import = f.read().strip().split("\n")
|
package_import = f.read().strip().split("\n")
|
||||||
except:
|
except:
|
||||||
@ -162,7 +163,8 @@ def join(f):
|
|||||||
|
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
candidates = get_all_imports(args['<path>'])
|
encoding = args.get('encoding')
|
||||||
|
candidates = get_all_imports(args['<path>'], encoding=encoding)
|
||||||
candidates = get_pkg_names(candidates)
|
candidates = get_pkg_names(candidates)
|
||||||
logging.debug("Found imports: " + ", ".join(candidates))
|
logging.debug("Found imports: " + ", ".join(candidates))
|
||||||
pypi_server = "https://pypi.python.org/pypi/"
|
pypi_server = "https://pypi.python.org/pypi/"
|
||||||
@ -171,7 +173,7 @@ def init(args):
|
|||||||
pypi_server = args["--pypi-server"]
|
pypi_server = args["--pypi-server"]
|
||||||
|
|
||||||
if args["--proxy"]:
|
if args["--proxy"]:
|
||||||
proxy = {'http':args["--proxy"], 'https':args["--proxy"]}
|
proxy = {'http': args["--proxy"], 'https': args["--proxy"]}
|
||||||
|
|
||||||
if args["--use-local"]:
|
if args["--use-local"]:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
@ -190,7 +192,6 @@ def init(args):
|
|||||||
path = (args["--savepath"] if args["--savepath"] else
|
path = (args["--savepath"] if args["--savepath"] else
|
||||||
os.path.join(args['<path>'], "requirements.txt"))
|
os.path.join(args['<path>'], "requirements.txt"))
|
||||||
|
|
||||||
|
|
||||||
if not args["--savepath"] and not args["--force"] and os.path.exists(path):
|
if not args["--savepath"] and not args["--force"] and os.path.exists(path):
|
||||||
logging.warning("Requirements.txt already exists, "
|
logging.warning("Requirements.txt already exists, "
|
||||||
"use --force to overwrite it")
|
"use --force to overwrite it")
|
||||||
|
@ -105,11 +105,9 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
import_name_without_aliases, expected_import_name_without_alias)
|
import_name_without_aliases, expected_import_name_without_alias)
|
||||||
|
|
||||||
|
|
||||||
def test_custom_pypi_server(self):
|
def test_custom_pypi_server(self):
|
||||||
self.assertRaises(requests.exceptions.MissingSchema, pipreqs.init, {'<path>': self.project, '--savepath': None,
|
self.assertRaises(requests.exceptions.MissingSchema, pipreqs.init, {'<path>': self.project, '--savepath': None,
|
||||||
'--use-local': None, '--force': True, '--proxy':None, '--pypi-server':'nonexistent'})
|
'--use-local': None, '--force': True, '--proxy': None, '--pypi-server': 'nonexistent'})
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user