diff --git a/README.rst b/README.rst index caa3b8f..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 ------- @@ -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..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 @@ -30,7 +29,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,15 +54,18 @@ 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)) + return sorted(list(set(third_party_packages) - set(data))) 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') @@ -86,12 +88,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