Skip to content

Commit

Permalink
Merge pull request #642 from jbergknoff-10e/user-only
Browse files Browse the repository at this point in the history
Add pip-sync option to restrict attention to user-local directory.
  • Loading branch information
vphilippon authored Mar 19, 2018
2 parents 168f0da + 712823f commit 5c36a72
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
@click.option('--extra-index-url', multiple=True, help="Add additional index URL to search", envvar='PIP_EXTRA_INDEX_URL') # noqa
@click.option('--no-index', is_flag=True, help="Ignore package index (only looking at --find-links URLs instead)")
@click.option('-q', '--quiet', default=False, is_flag=True, help="Give less output")
@click.option('--user', 'user_only', is_flag=True, help="Restrict attention to user directory")
@click.argument('src_files', required=False, type=click.Path(exists=True), nargs=-1)
def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet, src_files):
def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet, user_only, src_files):
"""Synchronize virtual environment with requirements.txt."""
if not src_files:
if os.path.exists(DEFAULT_REQUIREMENTS_FILE):
Expand Down Expand Up @@ -56,7 +57,7 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet,
log.error(str(e))
sys.exit(2)

installed_dists = pip.get_installed_distributions(skip=[])
installed_dists = pip.get_installed_distributions(skip=[], user_only=user_only)
to_install, to_uninstall = sync.diff(requirements, installed_dists)

install_flags = []
Expand All @@ -69,6 +70,8 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet,
if extra_index_url:
for extra_index in extra_index_url:
install_flags.extend(['--extra-index-url', extra_index])
if user_only:
install_flags.append('--user')

sys.exit(sync.sync(to_install, to_uninstall, verbose=(not quiet), dry_run=dry_run,
install_flags=install_flags))

0 comments on commit 5c36a72

Please sign in to comment.