pypa/pip — Issue #391: "pip freeze -r" returns ValueError() if requirements file contains --find-links
Author: dasein
Created: 2011-12-03 07:14:51+00:00
State: open

It seems that pip freeze should not pass --find-links or --index-url to distribute/setuptools when inlined in a requirements file. Here is an easy way to repro the problem:

1) echo "--find-links http://foo.bar/" > /tmp/req.txt
2) pip freeze -r /tmp/req.txt

"""
Exception:
Traceback (most recent call last):
File "/Users/hpfennig/work/pip/pip/basecommand.py", line 95, in main
self.run(options, args)
File "/Users/hpfennig/work/pip/pip/commands/freeze.py", line 92, in run
line_req = InstallRequirement.from_line(line)
File "/Users/hpfennig/work/pip/pip/req.py", line 105, in from_line
return cls(req, comes_from, url=url)
File "/Users/hpfennig/work/pip/pip/req.py", line 39, in __init__
req = pkg_resources.Requirement.parse(req)
File "/Users/hpfennig/.virtualenvs/pip-bug-virt-env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2510, in parse
reqs = list(parse_requirements(s))
File "/Users/hpfennig/.virtualenvs/pip-bug-virt-env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2436, in parse_requirements
line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
File "/Users/hpfennig/.virtualenvs/pip-bug-virt-env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2404, in scan_list
raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', '--find-links http://foo.bar/', 'at', ' http://foo.bar/')

Storing complete log in /Users/hpfennig/.pip/pip.log
"""

I have a fix, but I am not sure this is the correct way to go about it. Would be happy to do an official pull request if needed.

diff --git a/pip/commands/freeze.py b/pip/commands/freeze.py
index 01b5df9..03ac80f 100644
--- a/pip/commands/freeze.py
+++ b/pip/commands/freeze.py
@@ -85,7 +85,9 @@ class FreezeCommand(Command):
elif (line.startswith('-r') or line.startswith('--requirement')
or line.startswith('-Z') or line.startswith('--always-unzip')
or line.startswith('-f') or line.startswith('-i')
- or line.startswith('--extra-index-url')):
+ or line.startswith('--extra-index-url')
+ or line.startswith('--find-links')
+ or line.startswith('--index-url')):
f.write(line)
continue
else: