Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --extra option for extra packages in requirements.txt file #377

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Usage
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--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
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
Expand Down
7 changes: 7 additions & 0 deletions pipreqs/pipreqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--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
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
Expand Down Expand Up @@ -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['<path>']
if input_path is None:
Expand All @@ -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"]
Expand All @@ -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:
candidates = list(set(candidates) | set(extra_pkgs))
logging.debug("Found imports: " + ", ".join(candidates))
pypi_server = "https://pypi.python.org/pypi/"
proxy = None
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pipreqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{'<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):
"""
Test --mode=no-pin
Expand Down