Repository: jazzband/pip-tools

Issue:
pip-sync fails to uninstall if find-links are set
```

Usage:   
  pip uninstall [options] <package> ...
  pip uninstall [options] -r <requirements file> ...

no such option: -f
Traceback (most recent call last):
  File "/tmp/foo/bin/pip-sync", line 11, in <module>
    sys.exit(cli())
  File "/tmp/foo/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/foo/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/tmp/foo/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/foo/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/tmp/foo/local/lib/python2.7/site-packages/piptools/scripts/sync.py", line 75, in cli
    pip_flags=pip_flags))
  File "/tmp/foo/local/lib/python2.7/site-packages/piptools/sync.py", line 137, in sync
    check_call(['pip', 'uninstall', '-y'] + pip_flags + sorted(to_uninstall))
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['pip', 'uninstall', '-y', u'-f', u'https://ternaris.com/pypi', 'bagbunker', 'marv']' returned non-zero exit status 2
```



Discussion:

Resolving patch:
diff --git a/piptools/scripts/sync.py b/piptools/scripts/sync.py
--- a/piptools/scripts/sync.py
+++ b/piptools/scripts/sync.py
@@ -61,8 +61,9 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, src_fi
     to_install, to_uninstall = sync.diff(requirements, installed_dists)
 
     pip_flags = []
+    install_flags = []
     for link in find_links or []:
-        pip_flags.extend(['-f', link])
+        install_flags.extend(['-f', link])
     if no_index:
         pip_flags.append('--no-index')
     if index_url:
@@ -72,4 +73,4 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, src_fi
             pip_flags.extend(['--extra-index-url', extra_index])
 
     sys.exit(sync.sync(to_install, to_uninstall, verbose=True, dry_run=dry_run,
-                       pip_flags=pip_flags))
+                       pip_flags=pip_flags, install_flags=install_flags))
diff --git a/piptools/sync.py b/piptools/sync.py
--- a/piptools/sync.py
+++ b/piptools/sync.py
@@ -115,7 +115,7 @@ def diff(compiled_requirements, installed_dists):
     return (to_install, to_uninstall)
 
 
-def sync(to_install, to_uninstall, verbose=False, dry_run=False, pip_flags=None):
+def sync(to_install, to_uninstall, verbose=False, dry_run=False, pip_flags=None, install_flags=None):
     """
     Install and uninstalls the given sets of modules.
     """
@@ -137,10 +137,12 @@ def sync(to_install, to_uninstall, verbose=False, dry_run=False, pip_flags=None)
             check_call(['pip', 'uninstall', '-y'] + pip_flags + sorted(to_uninstall))
 
     if to_install:
+        if install_flags is None:
+            install_flags = []
         if dry_run:
             click.echo("Would install:")
             for pkg in to_install:
                 click.echo("  {}".format(pkg))
         else:
-            check_call(['pip', 'install'] + pip_flags + sorted(to_install))
+            check_call(['pip', 'install'] + pip_flags + install_flags + sorted(to_install))
     return 0


Test patch: