The --format flag is only in pip 9 and later
So lets make that an implicit dependency.
git-svn-id: https://llvm.org/svn/llvm-project/zorg/trunk@324138 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/dep/dep.py b/dep/dep.py
index 3697177..d19e021 100644
--- a/dep/dep.py
+++ b/dep/dep.py
@@ -539,7 +539,16 @@
def verify(self):
"""Verify the packages in pip match this dependency."""
+
try:
+ pip_version = subprocess.check_output(["/usr/bin/env", "python", "-m", "pip", "--version"])
+ pip_tokens = pip_version.split()
+ assert pip_tokens[0] == "pip"
+ pip_version = Version(pip_tokens[1])
+
+ if pip_version < Version("9.0.0"):
+ raise MissingDependencyError("Version of pip too old.")
+
pip_package_config = json.loads(subprocess.check_output(["/usr/bin/env",
"python", "-m", "pip", "list", "--format=json"]))
except (subprocess.CalledProcessError, OSError):
diff --git a/dep/tests/test_dep.py b/dep/tests/test_dep.py
index adc3c77..ab8f8ff 100644
--- a/dep/tests/test_dep.py
+++ b/dep/tests/test_dep.py
@@ -237,8 +237,18 @@
assert b.command == "pip"
assert b.package == "pytest"
assert b.version_text == "3.3.1"
+
+ # Check an old version of pip raises a dependency error.
mocker.patch('dep.subprocess.check_output')
- dep.subprocess.check_output.return_value = open(here + '/assets/pip_output.json').read()
+ dep.subprocess.check_output.side_effect = ["pip 1.2.3 from /Python/pip-1.3.1-py2.7.egg (python 2.7)",
+ open(here + '/assets/pip_output.json').read()]
+ with pytest.raises(MissingDependencyError):
+ b.verify_and_act()
+
+ num_of_checks = 4
+ mocker.patch('dep.subprocess.check_output')
+ dep.subprocess.check_output.side_effect = ["pip 9.0.1 from /Python/pip-1.3.1-py2.7.egg (python 2.7)",
+ open(here + '/assets/pip_output.json').read()] * num_of_checks
b.verify_and_act()
assert dep.subprocess.check_output.called