mirror of https://github.com/pypa/pip
Allow --no-index and --find-links relative path in reqs file.
This commit is contained in:
parent
04f01f227e
commit
895bfee767
24
pip/index.py
24
pip/index.py
|
@ -20,7 +20,7 @@ from pip.util import Inf
|
|||
from pip.util import normalize_name, splitext
|
||||
from pip.exceptions import DistributionNotFound, BestVersionAlreadyInstalled
|
||||
from pip.backwardcompat import (WindowsError, BytesIO,
|
||||
Queue, httplib, urlparse,
|
||||
Queue, urlparse,
|
||||
URLError, HTTPError, u,
|
||||
product, url2pathname)
|
||||
from pip.backwardcompat import Empty as QueueEmpty
|
||||
|
@ -80,17 +80,17 @@ class PackageFinder(object):
|
|||
|
||||
for url in locations:
|
||||
is_path = os.path.exists(url)
|
||||
if url.startswith('file:'):
|
||||
if is_path:
|
||||
path = url
|
||||
else:
|
||||
path = url_to_path(url)
|
||||
if os.path.isdir(path):
|
||||
path = os.path.realpath(path)
|
||||
for item in os.listdir(path):
|
||||
sort_path(os.path.join(path, item))
|
||||
elif os.path.isfile(path):
|
||||
sort_path(path)
|
||||
path = None
|
||||
if is_path:
|
||||
path = url
|
||||
elif url.startswith('file:'):
|
||||
path = url_to_path(url)
|
||||
if path and os.path.isdir(path):
|
||||
path = os.path.realpath(path)
|
||||
for item in os.listdir(path):
|
||||
sort_path(os.path.join(path, item))
|
||||
elif path and os.path.isfile(path):
|
||||
sort_path(path)
|
||||
else:
|
||||
urls.append(url)
|
||||
return files, urls
|
||||
|
|
|
@ -1273,6 +1273,7 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None):
|
|||
skip_regex = options.skip_requirements_regex if options else None
|
||||
if skip_regex:
|
||||
skip_match = re.compile(skip_regex)
|
||||
reqs_file_dir = os.path.dirname(os.path.abspath(filename))
|
||||
filename, content = get_file_content(filename, comes_from=comes_from)
|
||||
for line_number, line in enumerate(content.splitlines()):
|
||||
line_number += 1
|
||||
|
@ -1304,6 +1305,10 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None):
|
|||
line = line[len('--find-links'):].strip().lstrip('=')
|
||||
## FIXME: it would be nice to keep track of the source of
|
||||
## the find_links:
|
||||
# support a find-links local path relative to a requirements file
|
||||
relative_to_reqs_file = os.path.join(reqs_file_dir, line)
|
||||
if os.path.exists(relative_to_reqs_file):
|
||||
line = relative_to_reqs_file
|
||||
if finder:
|
||||
finder.find_links.append(line)
|
||||
elif line.startswith('-i') or line.startswith('--index-url'):
|
||||
|
@ -1317,6 +1322,8 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None):
|
|||
line = line[len('--extra-index-url'):].strip().lstrip('=')
|
||||
if finder:
|
||||
finder.index_urls.append(line)
|
||||
elif line.startswith('--no-index'):
|
||||
finder.index_urls = []
|
||||
else:
|
||||
comes_from = '-r %s (line %s)' % (filename, line_number)
|
||||
if line.startswith('-e') or line.startswith('--editable'):
|
||||
|
|
|
@ -5,7 +5,6 @@ import textwrap
|
|||
import sys
|
||||
from os.path import abspath, join, curdir, pardir
|
||||
|
||||
from nose import SkipTest
|
||||
from nose.tools import assert_raises
|
||||
from mock import patch
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import textwrap
|
||||
|
||||
from tests.test_pip import reset_env, run_pip, pyversion, here, write_file
|
||||
|
||||
|
||||
def test_find_links_relative_path():
|
||||
"""Test find-links as a relative path."""
|
||||
e = reset_env()
|
||||
result = run_pip(
|
||||
'install',
|
||||
'parent==0.1',
|
||||
'--no-index',
|
||||
'--find-links',
|
||||
'packages/',
|
||||
cwd=here)
|
||||
egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
|
||||
initools_folder = e.site_packages / 'parent'
|
||||
assert egg_info_folder in result.files_created, str(result)
|
||||
assert initools_folder in result.files_created, str(result)
|
||||
|
||||
|
||||
def test_find_links_requirements_file_relative_path():
|
||||
"""Test find-links as a relative path to a reqs file."""
|
||||
e = reset_env()
|
||||
write_file('test-req.txt', textwrap.dedent("""
|
||||
--no-index
|
||||
--find-links=../../../packages/
|
||||
parent==0.1
|
||||
"""))
|
||||
result = run_pip(
|
||||
'install',
|
||||
'-r',
|
||||
e.scratch_path / "test-req.txt",
|
||||
cwd=here)
|
||||
egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
|
||||
initools_folder = e.site_packages / 'parent'
|
||||
assert egg_info_folder in result.files_created, str(result)
|
||||
assert initools_folder in result.files_created, str(result)
|
Loading…
Reference in New Issue