Fix readme, add more verbose output

This commit is contained in:
Vadim Kravcenko 2015-04-22 22:40:17 +02:00
parent 2ce5bc9ea9
commit 8c7604ad99
2 changed files with 7 additions and 2 deletions

View File

@ -25,7 +25,7 @@ Usage
Options: Options:
--savepath Supply custom path for requirements.txt --savepath Supply custom path for requirements.txt
--debug See debug output --debug See debug output
Example Example
------- -------
@ -35,6 +35,6 @@ Example
$ pipreqs /home/project/location $ pipreqs /home/project/location
Successfuly saved requirements file in: /home/project/location/requirements.txt Successfuly saved requirements file in: /home/project/location/requirements.txt
Why not pip freeze? Why not pip freeze?
-------- --------

View File

@ -23,6 +23,7 @@ REGEXP = [
def get_all_imports(start_path): def get_all_imports(start_path):
imports = [] imports = []
packages = [] packages = []
logging.debug('Traversing tree, start: %s', start_path)
for root, dirs, files in os.walk(start_path): for root, dirs, files in os.walk(start_path):
path = root.split('/') path = root.split('/')
packages.append(os.path.basename(root)) packages.append(os.path.basename(root))
@ -48,12 +49,14 @@ def get_all_imports(start_path):
to_append = item if "." not in item else item.split(".")[0] to_append = item if "." not in item else item.split(".")[0]
imports.append(to_append.strip()) imports.append(to_append.strip())
third_party_packages = set(imports) - set(set(packages) & set(imports)) third_party_packages = set(imports) - set(set(packages) & set(imports))
logging.debug('Found third-party packages: %s', third_party_packages)
with open(os.path.join(os.path.dirname(__file__), "stdlib"), "r") as f: with open(os.path.join(os.path.dirname(__file__), "stdlib"), "r") as f:
data = [x.strip() for x in f.readlines()] data = [x.strip() for x in f.readlines()]
return list(set(third_party_packages) - set(data)) return list(set(third_party_packages) - set(data))
def generate_requirements_file(path, imports): def generate_requirements_file(path, imports):
with open(path, "w") as ff: with open(path, "w") as ff:
logging.debug('Writing requirements to file %s', path)
for item in imports: for item in imports:
ff.write(item['name'] + "==" + item['version']) ff.write(item['name'] + "==" + item['version'])
ff.write("\n") ff.write("\n")
@ -64,6 +67,7 @@ def get_imports_info(imports):
try: try:
data = yarg.get(item) data = yarg.get(item)
except HTTPError: except HTTPError:
logging.debug('Package does not exist or network problems')
continue continue
if not data or len(data.release_ids) < 1: if not data or len(data.release_ids) < 1:
continue continue
@ -76,6 +80,7 @@ def init(args):
imports_with_info = get_imports_info(imports) imports_with_info = get_imports_info(imports)
path = args["--savepath"] if args["--savepath"] else os.path.join(args['<path>'],"requirements.txt") path = args["--savepath"] if args["--savepath"] else os.path.join(args['<path>'],"requirements.txt")
generate_requirements_file(path, imports_with_info) generate_requirements_file(path, imports_with_info)
print "Successfuly saved requirements file in: " + path
def main(): def main():
args = docopt(__doc__, version='xstat 0.1') args = docopt(__doc__, version='xstat 0.1')