summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-10-17 11:10:31 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-04 12:40:56 +0000
commit9821815de452583e3d948a6d15c28972049140b5 (patch)
tree67c70877ef137e3f59c2b6fd68062719ec6f910d
parentfd41f5736c8bc67b815a53e843c693247f25102f (diff)
downloadimport-9821815de452583e3d948a6d15c28972049140b5.tar.gz
Fulfil TODO: don't keyerror on invalid op
-rwxr-xr-ximport/pip_lorry.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/import/pip_lorry.py b/import/pip_lorry.py
index 3083ee6..13a84af 100755
--- a/import/pip_lorry.py
+++ b/import/pip_lorry.py
@@ -120,13 +120,20 @@ def filter_urls(urls):
# TODO: find a nicer way to do this
def specs_satisfied(version, specs):
+ def mapping_error(op):
+ # We parse ops with requirements-parser, so any invalid user input
+ # should be detected there. This really guards against
+ # the pip developers adding some new operation to a requirement.
+ error("Invalid op in spec: %s" % op)
+
opmap = {'==' : lambda x, y: x == y, '!=' : lambda x, y: x != y,
'<=' : lambda x, y: x <= y, '>=' : lambda x, y: x >= y,
'<': lambda x, y: x < y, '>' : lambda x, y: x > y}
- TODO: don't just key error if we don't recognise the op
+ def get_op_func(op):
+ return opmap[op] if op in opmap else lambda x, y: mapping_error(op)
- return all([opmap[op](version, sv) for (op, sv) in specs])
+ return all([get_op_func(op)(version, sv) for (op, sv) in specs])
def generate_tarball_lorry(requirement):
try: