From 8bc094cf9e922579bdc6aa42eaad9979d11b82ed Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 5 Jul 2018 09:48:55 +1000 Subject: [PATCH] Ignore empty requirements/constraints when building lower-constraints Some constraints files[1] contain valid data but we want to ignore them when generating a combined lower-constraints.txt, rather than erroring out: [tony@thor requirements]$ time .tox/venv/bin/build-lower-constraints ../*/lower-constraints.txt > tjmaxx.txt Traceback (most recent call last): File ".tox/venv/bin/build-lower-constraints", line 10, in sys.exit(main()) File "/home/tony/projects/openstack/openstack/requirements/openstack_requirements/cmds/build_lower_constraints.py", line 71, in main merged = list(merge_constraints_sets(constraints_sets)) File "/home/tony/projects/openstack/openstack/requirements/openstack_requirements/cmds/build_lower_constraints.py", line 53, in merge_constraints_sets val = max((c[0] for c in constraints), key=get_requirements_version) File "/home/tony/projects/openstack/openstack/requirements/openstack_requirements/cmds/build_lower_constraints.py", line 43, in get_requirements_version raise ValueError('could not find version for {}'.format(req)) ValueError: could not find version for Requirement(package='', location='', specifiers='', markers='', comment='# flake8==2.5.5', extras=frozenset()) Let's just ignore comments in those files. [1] http://git.openstack.org/cgit/openstack/zaqar/tree/lower-constraints.txt#n28 Change-Id: Ie347ab273a1b239d9d264704482d3202dc4e4c74 --- .../cmds/build_lower_constraints.py | 3 ++- .../tests/test_build_lower_constraints.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/openstack_requirements/cmds/build_lower_constraints.py b/openstack_requirements/cmds/build_lower_constraints.py index b79eaa1762..438270f5d7 100644 --- a/openstack_requirements/cmds/build_lower_constraints.py +++ b/openstack_requirements/cmds/build_lower_constraints.py @@ -48,7 +48,8 @@ def merge_constraints_sets(constraints_sets): all_constraints = collections.defaultdict(list) for constraints_set in constraints_sets: for constraint_name, constraint in constraints_set.items(): - all_constraints[constraint_name].extend(constraint) + if constraint_name: + all_constraints[constraint_name].extend(constraint) for constraint_name, constraints in sorted(all_constraints.items()): val = max((c[0] for c in constraints), key=get_requirements_version) yield val.to_line() diff --git a/openstack_requirements/tests/test_build_lower_constraints.py b/openstack_requirements/tests/test_build_lower_constraints.py index 75b2f3ac71..5f820f4885 100644 --- a/openstack_requirements/tests/test_build_lower_constraints.py +++ b/openstack_requirements/tests/test_build_lower_constraints.py @@ -55,3 +55,15 @@ class BuildLowerConstraintsTest(testtools.TestCase): expected, list(build_lower_constraints.merge_constraints_sets(inputs)) ) + + def test_one_input_file_with_comments(self): + inputs = [ + requirement.parse('package==1.2.3\n # package2==0.9.8'), + ] + expected = [ + 'package==1.2.3\n', + ] + self.assertEqual( + expected, + list(build_lower_constraints.merge_constraints_sets(inputs)) + )