From fb87e41b631f008716d622ab4a54e743de8b6ae0 Mon Sep 17 00:00:00 2001 From: Harri Berglund Date: Tue, 28 Apr 2015 20:16:02 +0300 Subject: [PATCH 1/4] Fix typos --- README.rst | 4 ++-- pipreqs/pipreqs.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index caa3b8f..6ce695a 100644 --- a/README.rst +++ b/README.rst @@ -47,9 +47,9 @@ Example $ pipreqs /home/project/location Looking for imports - Getting latest version of packages information from PyPi + Getting latest information about packages from PyPI Found third-party imports: flask, requests, sqlalchemy, docopt - Successfuly saved requirements file in: /home/project/location/requirements.txt + Successfully saved requirements file in /home/project/location/requirements.txt Why not pip freeze? ------------------- diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index cf7b14e..d03c3bf 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -86,12 +86,12 @@ def get_imports_info(imports): def init(args): print("Looking for imports") imports = get_all_imports(args['']) - print("Getting latest version of packages information from PyPi") + print("Getting latest information about packages from PyPI") imports_with_info = get_imports_info(imports) print("Found third-party imports: " + ", ".join(imports)) path = args["--savepath"] if args["--savepath"] else os.path.join(args[''], "requirements.txt") generate_requirements_file(path, imports_with_info) - print("Successfuly saved requirements file in: " + path) + print("Successfully saved requirements file in " + path) def main(): # pragma: no cover From 177c156b38091634334f7c3673e68bb92b6c467c Mon Sep 17 00:00:00 2001 From: Harri Berglund Date: Tue, 28 Apr 2015 20:54:47 +0300 Subject: [PATCH 2/4] Use str.format() --- pipreqs/pipreqs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index d03c3bf..9f33e4e 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -30,7 +30,7 @@ REGEXP = [ def get_all_imports(start_path): imports = [] packages = [] - logging.debug('Traversing tree, start: %s', start_path) + logging.debug('Traversing tree, start: {0}'.format(start_path)) for root, dirs, files in os.walk(start_path): packages.append(os.path.basename(root)) files = [fn for fn in files if os.path.splitext(fn)[1] == ".py"] @@ -55,7 +55,7 @@ def get_all_imports(start_path): to_append = item.partition(' as ')[0].partition('.')[0] imports.append(to_append.strip()) third_party_packages = set(imports) - set(set(packages) & set(imports)) - logging.debug('Found third-party packages: %s', third_party_packages) + logging.debug('Found third-party packages: {0}'.format(third_party_packages)) with open(os.path.join(os.path.dirname(__file__), "stdlib"), "r") as f: data = [x.strip() for x in f.readlines()] return list(set(third_party_packages) - set(data)) @@ -63,7 +63,10 @@ def get_all_imports(start_path): def generate_requirements_file(path, imports): with open(path, "w") as out_file: - logging.debug('Writing %d requirements to file %s', (len(imports), path)) + logging.debug('Writing {num} requirements to {file}'.format( + num=len(imports), + file=path + )) fmt = '{name} == {version}' out_file.write('\n'.join(fmt.format(**item) for item in imports) + '\n') From 57626670ce6d5e1ace4d0e4e9ee7c5e9c1152303 Mon Sep 17 00:00:00 2001 From: Harri Berglund Date: Tue, 28 Apr 2015 20:26:39 +0300 Subject: [PATCH 3/4] Return sorted list from get_all_imports() --- pipreqs/pipreqs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 9f33e4e..3578b47 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -58,7 +58,7 @@ def get_all_imports(start_path): logging.debug('Found third-party packages: {0}'.format(third_party_packages)) with open(os.path.join(os.path.dirname(__file__), "stdlib"), "r") as f: data = [x.strip() for x in f.readlines()] - return list(set(third_party_packages) - set(data)) + return sorted(list(set(third_party_packages) - set(data))) def generate_requirements_file(path, imports): From b8a88e3c94e1c06f3ca3f02fa0db4754d407127b Mon Sep 17 00:00:00 2001 From: Harri Berglund Date: Tue, 28 Apr 2015 22:37:06 +0300 Subject: [PATCH 4/4] Update help text --- README.rst | 6 +++--- pipreqs/pipreqs.py | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 6ce695a..25867f6 100644 --- a/README.rst +++ b/README.rst @@ -34,11 +34,11 @@ Usage :: Usage: - pipreqs [options] + pipreqs [options] Options: - --savepath Supply custom path for requirements.txt - --debug See debug output + --debug Print debug information + --savepath Save the list of requirements in the given file Example ------- diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 3578b47..842e163 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -3,12 +3,11 @@ """pipreqs - Generate pip requirements.txt file based on imports Usage: - pipreqs - pipreqs [options] + pipreqs [options] Options: - --debug prints debug information. - --savepath path to requirements.txt (Optional) + --debug Print debug information + --savepath Save the list of requirements in the given file """ from __future__ import print_function import os