Add --extra option

This commit is contained in:
Temerold 2023-06-17 01:23:02 +02:00
parent a1f83d27d9
commit 1df61bee04
3 changed files with 27 additions and 0 deletions

View File

@ -46,6 +46,7 @@ Usage
$ export HTTPS_PROXY="https://10.10.1.10:1080" $ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information --debug Print debug information
--ignore <dirs>... Ignore extra directories, each separated by a comma --ignore <dirs>... Ignore extra directories, each separated by a comma
--extra <packages>... Add extra packages, each separated by a comma
--no-follow-links Do not follow symbolic links in the project --no-follow-links Do not follow symbolic links in the project
--encoding <charset> Use encoding parameter for file open --encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file --savepath <file> Save the list of requirements in the given file

View File

@ -20,6 +20,7 @@ Options:
$ export HTTPS_PROXY="https://10.10.1.10:1080" $ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information --debug Print debug information
--ignore <dirs>... Ignore extra directories, each separated by a comma --ignore <dirs>... Ignore extra directories, each separated by a comma
--extra <modules>... Add extra modules, each separated by a comma
--no-follow-links Do not follow symbolic links in the project --no-follow-links Do not follow symbolic links in the project
--encoding <charset> Use encoding parameter for file open --encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file --savepath <file> Save the list of requirements in the given file
@ -434,6 +435,7 @@ def dynamic_versioning(scheme, imports):
def init(args): def init(args):
encoding = args.get('--encoding') encoding = args.get('--encoding')
extra_ignore_dirs = args.get('--ignore') extra_ignore_dirs = args.get('--ignore')
extra_pkgs = args.get('--extra')
follow_links = not args.get('--no-follow-links') follow_links = not args.get('--no-follow-links')
input_path = args['<path>'] input_path = args['<path>']
if input_path is None: if input_path is None:
@ -442,6 +444,9 @@ def init(args):
if extra_ignore_dirs: if extra_ignore_dirs:
extra_ignore_dirs = extra_ignore_dirs.split(',') extra_ignore_dirs = extra_ignore_dirs.split(',')
if extra_pkgs:
extra_pkgs = extra_pkgs.split(',')
path = (args["--savepath"] if args["--savepath"] else path = (args["--savepath"] if args["--savepath"] else
os.path.join(input_path, "requirements.txt")) os.path.join(input_path, "requirements.txt"))
if (not args["--print"] if (not args["--print"]
@ -457,6 +462,8 @@ def init(args):
extra_ignore_dirs=extra_ignore_dirs, extra_ignore_dirs=extra_ignore_dirs,
follow_links=follow_links) follow_links=follow_links)
candidates = get_pkg_names(candidates) candidates = get_pkg_names(candidates)
if extra_pkgs is not None:
candidates = list(set(candidates) | set(extra_pkgs))
logging.debug("Found imports: " + ", ".join(candidates)) logging.debug("Found imports: " + ", ".join(candidates))
pypi_server = "https://pypi.python.org/pypi/" pypi_server = "https://pypi.python.org/pypi/"
proxy = None proxy = None

View File

@ -217,6 +217,25 @@ class TestPipreqs(unittest.TestCase):
for item in ['click', 'getpass']: for item in ['click', 'getpass']:
self.assertFalse(item.lower() in data) self.assertFalse(item.lower() in data)
def test_extra_module(self):
"""
Test --extra parameter
"""
pipreqs.init(
{'<path>': 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): def test_dynamic_version_no_pin_scheme(self):
""" """
Test --mode=no-pin Test --mode=no-pin