pypa/pip — Issue #406: Improper relative urls resolution
Author: nolar
Created: 2011-12-16 09:06:09+00:00
State: open

When you 'pip install' from requirements on any http server like this:

```sh
pip install -v -r http://myhost/projectname/bootstrapper.txt
```
And if that bootstrapper.txt refers to other http requirements like this:

```
-r http://otherhost/projectname.git/blobs/requirements.txt
```

In this case pip hangs, and if you interrupt it with Ctrl-C, you see an infinite recursion there:

```
Operation cancelled by user
Exception information:
Traceback (most recent call last):
File "/Users/nolar/tst/envvv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/basecommand.py", l
ine 126, in main
self.run(options, args)
File "/Users/nolar/tst/envvv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/commands/install.p
y", line 200, in run
for req in parse_requirements(filename, finder=finder, options=options):
File "/Users/nolar/tst/envvv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 1228, in parse_requirements
for item in parse_requirements(req_url, finder, comes_from=filename, options=options):
File "/Users/nolar/tst/envvv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 1228, in parse_requirements
for item in parse_requirements(req_url, finder, comes_from=filename, options=options):
File "/Users/nolar/tst/envvv/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 1228, in parse_requirements
……………………………
```

This happens because of this line in the code in pip/req.py:parse_requirements():

```python
# Relative to a URL
req_url = urlparse.urljoin(req_url, filename)
```

Where filename is the initial url (bootstrapper.txt), and req_url is a url from that file (requirements.txt).

The problem is that the arguments are switched here. They should go in reverse order: base url first, new url then, according to http://docs.python.org/library/urlparse.html?highlight=urlparse.urljoin#urlparse.urljoin

And after this line, pip tries to fetch bootstrapper.txt again, instead of the desired requirements.txt. And goes into the recursion.