From 1df61bee0488fd8cba3d4c3aa3efb8cf706fe58d Mon Sep 17 00:00:00 2001 From: Temerold Date: Sat, 17 Jun 2023 01:23:02 +0200 Subject: [PATCH 1/3] Add --extra option --- README.rst | 1 + pipreqs/pipreqs.py | 7 +++++++ tests/test_pipreqs.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/README.rst b/README.rst index 16c477a..19347ec 100644 --- a/README.rst +++ b/README.rst @@ -46,6 +46,7 @@ Usage $ export HTTPS_PROXY="https://10.10.1.10:1080" --debug Print debug information --ignore ... Ignore extra directories, each separated by a comma + --extra ... Add extra packages, each separated by a comma --no-follow-links Do not follow symbolic links in the project --encoding Use encoding parameter for file open --savepath Save the list of requirements in the given file diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 8182115..d8d212c 100644 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -20,6 +20,7 @@ $ export HTTPS_PROXY="https://10.10.1.10:1080" --debug Print debug information --ignore ... Ignore extra directories, each separated by a comma + --extra ... Add extra modules, each separated by a comma --no-follow-links Do not follow symbolic links in the project --encoding Use encoding parameter for file open --savepath Save the list of requirements in the given file @@ -434,6 +435,7 @@ def dynamic_versioning(scheme, imports): def init(args): encoding = args.get('--encoding') extra_ignore_dirs = args.get('--ignore') + extra_pkgs = args.get('--extra') follow_links = not args.get('--no-follow-links') input_path = args[''] if input_path is None: @@ -442,6 +444,9 @@ def init(args): if extra_ignore_dirs: extra_ignore_dirs = extra_ignore_dirs.split(',') + if extra_pkgs: + extra_pkgs = extra_pkgs.split(',') + path = (args["--savepath"] if args["--savepath"] else os.path.join(input_path, "requirements.txt")) if (not args["--print"] @@ -457,6 +462,8 @@ def init(args): extra_ignore_dirs=extra_ignore_dirs, follow_links=follow_links) candidates = get_pkg_names(candidates) + if extra_pkgs is not None: + candidates = list(set(candidates) | set(extra_pkgs)) logging.debug("Found imports: " + ", ".join(candidates)) pypi_server = "https://pypi.python.org/pypi/" proxy = None diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index f82d3db..0ffdd48 100644 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -217,6 +217,25 @@ def test_ignored_directory(self): for item in ['click', 'getpass']: self.assertFalse(item.lower() in data) + def test_extra_module(self): + """ + Test --extra parameter + """ + pipreqs.init( + {'': self.project_with_ignore_directory, '--savepath': None, + '--print': False, '--use-local': None, '--force': True, + '--proxy': None, '--pypi-server': None, + '--extra': 'example,example2', + '--diff': None, + '--clean': None, + '--mode': None + } + ) + with open(os.path.join(self.project_with_ignore_directory, "requirements.txt"), "r") as f: + data = f.read().lower() + for item in ['example,example2']: + self.assertFalse(item.lower() in data) + def test_dynamic_version_no_pin_scheme(self): """ Test --mode=no-pin From a728ffaf58abbdf5a9b1c2078e02f2edf91938f3 Mon Sep 17 00:00:00 2001 From: Temerold Date: Sat, 17 Jun 2023 01:35:54 +0200 Subject: [PATCH 2/3] Change "packages" to "modules" --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 19347ec..51a8bcf 100644 --- a/README.rst +++ b/README.rst @@ -46,7 +46,7 @@ Usage $ export HTTPS_PROXY="https://10.10.1.10:1080" --debug Print debug information --ignore ... Ignore extra directories, each separated by a comma - --extra ... Add extra packages, each separated by a comma + --extra ... Add extra modules, each separated by a comma --no-follow-links Do not follow symbolic links in the project --encoding Use encoding parameter for file open --savepath Save the list of requirements in the given file From 8f3515462b99ad3cdf3b7f2a0110a3a54fcd4694 Mon Sep 17 00:00:00 2001 From: Temerold Date: Sat, 17 Jun 2023 01:36:50 +0200 Subject: [PATCH 3/3] Remove reduntant logic --- pipreqs/pipreqs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index d8d212c..11d1aeb 100644 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -462,7 +462,7 @@ def init(args): extra_ignore_dirs=extra_ignore_dirs, follow_links=follow_links) candidates = get_pkg_names(candidates) - if extra_pkgs is not None: + if extra_pkgs: candidates = list(set(candidates) | set(extra_pkgs)) logging.debug("Found imports: " + ", ".join(candidates)) pypi_server = "https://pypi.python.org/pypi/"