summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorholger krekel <holger@merlinux.eu>2015-03-09 08:10:45 +0100
committerholger krekel <holger@merlinux.eu>2015-03-09 08:10:45 +0100
commita85561dd62c86929b60c011ec64187484a1120e4 (patch)
treeae1fa56d4caf5294b832cbb16d60a912af53f89a
parent3fd43ad85ec200a199bf83f30c66499aacb0d4ac (diff)
parent0765d8d77af6e5bbe16e79d4aff947c8dcd46e91 (diff)
downloadtox-a85561dd62c86929b60c011ec64187484a1120e4.tar.gz
Merged in sontek/tox/fix-force-dep-with-reqs-file-with-pip (pull request #136)
Support force dependencies with requirements.txt using pip
-rw-r--r--tests/test_config.py44
-rw-r--r--tox/_config.py30
2 files changed, 71 insertions, 3 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index f957771..c030db8 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -1423,6 +1423,50 @@ class TestCmdInvocation:
r'*deps=*dep1, dep2==5.0*',
])
+ def test_force_dep_with_requirements_txt_file(self, cmd, initproj):
+ """
+ Make sure we can override dependencies configured in external reqs.txt
+ when using the command line option --force-dep.
+ """
+ initproj("example123-0.5", filedefs={
+ 'tox.ini': '''
+ [tox]
+
+ [testenv]
+ deps=
+ dep1==1.0
+ -r{toxinidir}/reqs.txt
+ ''',
+ 'reqs.txt': '''
+ -e git://hello/world/git#egg=Hello
+ # comment
+ dep2>=2.0 # comment
+
+
+ -i http://index.local/
+ dep3
+ dep4==4.0
+ -r reqs2.txt
+ ''',
+ 'reqs2.txt': '''
+ dep5>=2.2
+ '''
+ })
+ config = parseconfig(
+ ['--force-dep=dep1==1.5', '--force-dep=dep2==2.1',
+ '--force-dep=dep3==3.0'])
+ assert config.option.force_dep == [
+ 'dep1==1.5', 'dep2==2.1', 'dep3==3.0']
+
+ deps = config.envconfigs['python'].deps
+ assert len(deps) == 6
+ expected = ['dep1==1.5', 'Hello', 'dep2==2.1',
+ 'dep3==3.0', 'dep4', 'dep5']
+
+ for index, dep in enumerate(deps):
+ assert dep.name == expected[index]
+
+
class TestArgumentParser:
def test_dash_e_single_1(self):
diff --git a/tox/_config.py b/tox/_config.py
index 3d26686..b7afc62 100644
--- a/tox/_config.py
+++ b/tox/_config.py
@@ -9,7 +9,8 @@ import pkg_resources
import itertools
from tox.interpreters import Interpreters
-
+from pip.req.req_file import parse_requirements
+from pip.download import PipSession
import py
import tox
@@ -371,6 +372,8 @@ class parseini:
vc.whitelist_externals = reader.getlist(section,
"whitelist_externals")
vc.deps = []
+ requirement_files = []
+
for depline in reader.getlist(section, "deps"):
m = re.match(r":(\w+):\s*(\S+)", depline)
if m:
@@ -379,8 +382,29 @@ class parseini:
else:
name = depline.strip()
ixserver = None
- name = self._replace_forced_dep(name, config)
- vc.deps.append(DepConfig(name, ixserver))
+
+
+ # We want to parse requirements.txt files last so that
+ # we can process them with forced dependencies
+ if name[:2] == '-r':
+ fname = name[2:].strip()
+ requirement_files.append(fname)
+ else:
+ name = self._replace_forced_dep(name, config)
+ vc.deps.append(DepConfig(name, ixserver))
+
+ pip_session = PipSession()
+
+ for requirement_file in requirement_files:
+ req_deps = parse_requirements(
+ requirement_file,
+ session=pip_session
+ )
+
+ for r in req_deps:
+ name = self._replace_forced_dep(r.name, config)
+ vc.deps.append(DepConfig(name, ixserver))
+
vc.distribute = reader.getbool(section, "distribute", False)
vc.sitepackages = self.config.option.sitepackages or \
reader.getbool(section, "sitepackages", False)