Merge pull request #30 from hdformat/master

fix for windows, update readme and  fix lint warnning
This commit is contained in:
Vadim Kravcenko 2015-10-20 22:03:21 +02:00
commit 2ffa4d2bf0
3 changed files with 23 additions and 20 deletions

View File

@ -38,9 +38,13 @@ Usage
Options:
--use-local Use ONLY local package information instead of querying PyPI
--pypi-server Use custom PyPi server
--proxy Use Proxy, parameter will be passed to requests library
--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
-------

View File

@ -10,6 +10,7 @@ Options:
--pypi-server Use custom PyPi server
--proxy Use Proxy, parameter will be passed to requests library
--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
"""
@ -32,7 +33,7 @@ REGEXP = [
]
def get_all_imports(path):
def get_all_imports(path, encoding=None):
imports = []
candidates = []
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]
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(
filter_line, map(lambda l: l.partition("#")[0].strip(), f))
for line in lines:
@ -111,7 +112,7 @@ def get_locally_installed_packages():
for item in files:
if "top_level" in item:
with open(os.path.join(root, item), "r") as f:
package = root.split("/")[-1].split("-")
package = root.split(os.sep)[-1].split("-")
try:
package_import = f.read().strip().split("\n")
except:
@ -162,7 +163,8 @@ def join(f):
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)
logging.debug("Found imports: " + ", ".join(candidates))
pypi_server = "https://pypi.python.org/pypi/"
@ -190,7 +192,6 @@ def init(args):
path = (args["--savepath"] if args["--savepath"] else
os.path.join(args['<path>'], "requirements.txt"))
if not args["--savepath"] and not args["--force"] and os.path.exists(path):
logging.warning("Requirements.txt already exists, "
"use --force to overwrite it")

View File

@ -105,12 +105,10 @@ class TestPipreqs(unittest.TestCase):
self.assertEqual(
import_name_without_aliases, expected_import_name_without_alias)
def test_custom_pypi_server(self):
self.assertRaises(requests.exceptions.MissingSchema, pipreqs.init, {'<path>': self.project, '--savepath': None,
'--use-local': None, '--force': True, '--proxy': None, '--pypi-server': 'nonexistent'})
def tearDown(self):
try:
os.remove(self.requirements_path)