Пример #1
0
 def test_check_compatible(self):
     global_reqs = requirement.parse("foo>=1.2\n")
     good_constraints = requirement.parse("foo===1.2.5\n")
     bad_constraints = requirement.parse("foo===1.1.2\n")
     self.assertEqual([], check_compatible(global_reqs, good_constraints))
     self.assertNotEqual(
         [], check_compatible(global_reqs, bad_constraints))
Пример #2
0
 def test_neither(self):
     global_reqs = requirement.parse("foo>=1.2\nbar>2.0\n")
     good_constraints = requirement.parse("foo===1.2.5\n")
     blacklist = requirement.parse('flake8\nhacking')
     results = list(constraints.check_blacklist_coverage(
         global_reqs, good_constraints, blacklist, 'test'))
     self.assertEqual(1, len(results))
     self.assertIn("'bar' appears in global-requirements.txt", results[0])
Пример #3
0
 def test_blacklisted(self):
     global_reqs = requirement.parse("foo>=1.2\nbar>2.0\n")
     good_constraints = requirement.parse("foo===1.2.5\n")
     blacklist = requirement.parse('flake8\nhacking\nbar')
     self.assertEqual(
         [],
         list(constraints.check_blacklist_coverage(
             global_reqs, good_constraints, blacklist, 'test'))
     )
 def test_two_input_file_differ(self):
     inputs = [
         requirement.parse('package==1.2.3'),
         requirement.parse('package==4.5.6'),
     ]
     expected = [
         'package==4.5.6\n',
     ]
     self.assertEqual(
         expected,
         list(build_lower_constraints.merge_constraints_sets(inputs))
     )
Пример #5
0
 def test_blacklisted(self):
     # If the package is blacklisted, everything is OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2,!=1.4')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse('name'),
             global_reqs=global_reqs,
         )
     )
Пример #6
0
 def test_not_in_global_list(self):
     # If the package is not in the global list, that is an error.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2,!=1.4')['name']
     ]
     global_reqs = check.get_global_reqs('')
     self.assertTrue(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #7
0
 def test_new_item_matches_global_list(self):
     # If the new item matches the global list exactly that is OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2,!=1.4')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #8
0
def _do_main(
        root, source, suffix, softupdate, hacking, stdout, verbose,
        non_std_reqs):
    """No options or environment variable access from here on in."""
    proj = project.read(root)
    global_req_content = open(
        os.path.join(source, 'global-requirements.txt'), 'rt').read()
    global_reqs = requirement.parse(global_req_content)
    blacklist_content = open(
        os.path.join(source, 'blacklist.txt'), 'rt').read()
    blacklist = requirement.parse(blacklist_content)
    actions = _process_project(
        proj, global_reqs, suffix, softupdate, hacking, non_std_reqs,
        blacklist)
    project.write(proj, actions, stdout=stdout, verbose=verbose)
Пример #9
0
 def test_non_requirement(self):
     global_reqs = {}
     good_constraints = requirement.parse("foo===1.2.5\n")
     self.assertEqual(
         [],
         constraints.check_compatible(global_reqs, good_constraints)
     )
Пример #10
0
 def test_missing_exclusion(self):
     req = requirement.parse('name>=1.2')['name'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         ))
Пример #11
0
 def test_extra_exclusion(self):
     req = requirement.parse('name>=1.2,!=1.4,!=1.5')['name'][0][0]
     self.assertFalse(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         ))
Пример #12
0
 def test_name_mismatch(self):
     req = requirement.parse('wrongname>=1.2,!=1.4')['wrongname'][0][0]
     self.assertFalse(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         ))
Пример #13
0
 def test_constraints_with_markers(self):
     constraints_content = textwrap.dedent("""
     name==1.1;python_version=='2.7'
     name==2.0;python_version=='3.5'
     name==2.0;python_version=='3.6'
     """)
     project_data = {
         'requirements': {
             'requirements.txt':
             textwrap.dedent("""
             name>=1.1,!=1.2;python_version=='2.7'
             name>=2.0;python_version=='3.5'
             name>=2.0;python_version=='3.6'
             """),
         },
         'lower-constraints.txt': constraints_content,
     }
     head_reqs = check.RequirementsList('testproj', project_data)
     head_reqs.process(False)
     self.assertFalse(
         check.validate_lower_constraints(
             req_list=head_reqs,
             constraints=project_data['lower-constraints.txt'],
             blacklist=requirement.parse(''),
         ))
Пример #14
0
 def test_multiple_lines_separated_in_project(self):
     global_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     project_content = textwrap.dedent("""\
         foo<1.8;python_version=='2.7'
         # mumbo gumbo
         foo>0.9;python_version!='2.7'
         """)
     global_reqs = requirement.parse(global_content)
     project_reqs = list(requirement.to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     self.assertEqual(requirement.Requirements([
         requirement.Requirement(
             'foo', '', '<2', "python_version=='2.7'", ''),
         requirement.Requirement(
             'foo', '', '>1', "python_version!='2.7'", ''),
         requirement.Requirement(
             '', '', '', '', "# mumbo gumbo")]),
         reqs)
     self.assertEqual(project.StdOut(
         "    foo<1.8;python_version=='2.7'  ->   "
         "foo<2;python_version=='2.7'\n"), actions[2])
     self.assertEqual(project.StdOut(
         "    foo>0.9;python_version!='2.7'  ->   "
         "foo>1;python_version!='2.7'\n"), actions[3])
     self.assertThat(actions, matchers.HasLength(4))
Пример #15
0
    def test_extras_no_change(self):
        global_content = textwrap.dedent(u"""\
            foo<2;python_version=='2.7' # BSD
            foo>1;python_version!='2.7'
            freddy
            """)
        setup_cfg = textwrap.dedent(u"""\
            [metadata]
            name = openstack.requirements

            [extras]
            test =
              foo<2:python_version=='2.7' # BSD
              foo>1:python_version!='2.7'
            opt =
              freddy
            """)
        proj = {}
        proj['root'] = '/dev/null'
        proj['requirements'] = {}
        proj['setup.cfg'] = setup_cfg
        global_reqs = requirement.parse(global_content)
        actions = update._copy_requires(
            u'', False, False, proj, global_reqs, False)
        self.assertEqual([
            project.Verbose('Syncing extra [opt]'),
            project.Verbose('Syncing extra [test]'),
            project.File('setup.cfg', setup_cfg)], actions)
Пример #16
0
 def test_new_item_lower_min(self):
     # If the new item has a lower minimum value than the global
     # list, that is OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.1,!=1.4')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #17
0
 def test_constraints_with_markers(self):
     constraints_content = textwrap.dedent("""
     name==1.1;python_version=='2.7'
     name==2.0;python_version=='3.5'
     name==2.0;python_version=='3.6'
     """)
     project_data = {
         'requirements': {
             'requirements.txt': textwrap.dedent("""
             name>=1.1,!=1.2;python_version=='2.7'
             name>=2.0;python_version=='3.5'
             name>=2.0;python_version=='3.6'
             """),
         },
         'lower-constraints.txt': constraints_content,
     }
     head_reqs = check.RequirementsList('testproj', project_data)
     head_reqs.process(False)
     self.assertFalse(
         check.validate_lower_constraints(
             req_list=head_reqs,
             constraints=project_data['lower-constraints.txt'],
             blacklist=requirement.parse(''),
         )
     )
Пример #18
0
 def test_unchanged(self):
     # If the line matches the value in the branch list everything
     # is OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2,!=1.4')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #19
0
    def test_extras_no_change(self):
        global_content = textwrap.dedent(u"""\
            foo<2;python_version=='2.7' # BSD
            foo>1;python_version!='2.7'
            freddy
            """)
        setup_cfg = textwrap.dedent(u"""\
            [metadata]
            name = openstack.requirements

            [extras]
            test =
              foo<2:python_version=='2.7' # BSD
              foo>1:python_version!='2.7'
            opt =
              freddy
            """)
        proj = {}
        proj['root'] = '/dev/null'
        proj['requirements'] = {}
        proj['setup.cfg'] = setup_cfg
        global_reqs = requirement.parse(global_content)
        actions = update._copy_requires(u'', False, False, proj, global_reqs,
                                        False)
        self.assertEqual([
            project.Verbose('Syncing extra [opt]'),
            project.Verbose('Syncing extra [test]'),
            project.File('setup.cfg', setup_cfg)
        ], actions)
Пример #20
0
 def test_match(self):
     req = requirement.parse('name>=1.2,!=1.4')['name'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         ))
Пример #21
0
 def test_multiple_lines_separated_in_project(self):
     global_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     project_content = textwrap.dedent("""\
         foo<1.8;python_version=='2.7'
         # mumbo gumbo
         foo>0.9;python_version!='2.7'
         """)
     global_reqs = requirement.parse(global_content)
     project_reqs = list(requirement.to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(global_reqs,
                                                    project_reqs, 'f',
                                                    False, False, False)
     self.assertEqual(
         requirement.Requirements([
             requirement.Requirement('foo', '', '<2',
                                     "python_version=='2.7'", ''),
             requirement.Requirement('foo', '', '>1',
                                     "python_version!='2.7'", ''),
             requirement.Requirement('', '', '', '', "# mumbo gumbo")
         ]), reqs)
     self.assertEqual(
         project.StdOut("    foo<1.8;python_version=='2.7'  ->   "
                        "foo<2;python_version=='2.7'\n"), actions[2])
     self.assertEqual(
         project.StdOut("    foo>0.9;python_version!='2.7'  ->   "
                        "foo>1;python_version!='2.7'\n"), actions[3])
     self.assertThat(actions, matchers.HasLength(4))
Пример #22
0
 def test_blacklisted_mismatch(self):
     # If the package is blacklisted, it doesn't matter if the
     # version matches.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.5')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse('name'),
             global_reqs=global_reqs,
         )
     )
Пример #23
0
 def test_new_item_extra_exclusion(self):
     # If the new item includes an exclusion that is not present in
     # the global list that is not OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2,!=1.4,!=1.5')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertTrue(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #24
0
 def test_new_item_missing_exclusion(self):
     # If the new item does not include an exclusion that is
     # present in the global list that is OK.
     reqs = [
         r
         for r, line in requirement.parse('name>=1.2')['name']
     ]
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #25
0
 def test_missing_exclusion(self):
     req = requirement.parse('name>=1.2')['name'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         )
     )
Пример #26
0
 def test_min_mismatch(self):
     req = requirement.parse('name>=1.3,!=1.4')['name'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         )
     )
Пример #27
0
 def test_extra_exclusion(self):
     req = requirement.parse('name>=1.2,!=1.4,!=1.5')['name'][0][0]
     self.assertFalse(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         )
     )
Пример #28
0
 def test_match_without_python3_markers(self):
     req = requirement.parse(
         textwrap.dedent("""
     withmarker>=1.5'
     """))['withmarker'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req, self.global_reqs['withmarker'], allow_3_only=True))
Пример #29
0
 def test_name_mismatch(self):
     req = requirement.parse('wrongname>=1.2,!=1.4')['wrongname'][0][0]
     self.assertFalse(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['name'],
         )
     )
Пример #30
0
 def test_requirements_policy_pass(self):
     content = textwrap.dedent("""\
         cffi!=1.1.2
         other
         """)
     reqs = requirement.parse(content)
     policy_check = [x for x in requirement.check_reqs_bounds_policy(reqs)]
     self.assertEqual(len(policy_check), 0)
Пример #31
0
 def test_replace_non_canonical(self):
     new_req = '-e file:///path#egg=foo_baz'
     reqs = requirement.parse("foo-baz===1.0.2\n")
     res = edit.edit(reqs, 'foo_baz', new_req)
     self.assertEqual(
         res,
         requirement.Requirements(
             [requirement.Requirement('', '', '', '', new_req)]))
 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)))
Пример #33
0
 def test_not_in_global_list(self):
     # If the package is not in the global list, that is an error.
     reqs = [r for r, line in requirement.parse('name>=1.2,!=1.4')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': 'name>=1.2,!=1.4'
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('')
     self.assertTrue(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         ))
Пример #34
0
 def test_requirements_policy_fail(self):
     content = textwrap.dedent("""\
         cffi>=1.1.1,!=1.1.0
         other>=1,>=2,!=1.1.0
         """)
     reqs = requirement.parse(content)
     self.assertEqual([
         'Requirement cffi should not include a >= specifier',
         'Requirement other should not include a >= specifier'],
         sorted([x for x in requirement.check_reqs_bounds_policy(reqs)]))
Пример #35
0
 def test_new_item_matches_global_list(self):
     # If the new item matches the global list exactly that is OK.
     reqs = [r for r, line in requirement.parse('name>=1.2,!=1.4')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': ''
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         ))
Пример #36
0
 def test_match_with_markers(self):
     req = requirement.parse(
         textwrap.dedent("""
     withmarker>=1.5;python_version=='3.5'
     """))['withmarker'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['withmarker'],
         ))
Пример #37
0
 def test_blacklisted(self):
     # If the package is blacklisted, everything is OK.
     reqs = [r for r, line in requirement.parse('name>=1.2,!=1.4')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': 'name>=1.2,!=1.4'
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse('name'),
             global_reqs=global_reqs,
         ))
Пример #38
0
def _do_main(root, source, suffix, softupdate, hacking, stdout, verbose,
             non_std_reqs):
    """No options or environment variable access from here on in."""
    proj = project.read(root)
    global_req_content = open(os.path.join(source, 'global-requirements.txt'),
                              'rt').read()
    global_reqs = requirement.parse(global_req_content)
    actions = _process_project(proj, global_reqs, suffix, softupdate, hacking,
                               non_std_reqs)
    project.write(proj, actions, stdout=stdout, verbose=verbose)
Пример #39
0
 def test_multiline(self):
     content = textwrap.dedent(
         """\
         oslo.config>=1.11.0     # Apache-2.0
         oslo.concurrency>=2.3.0 # Apache-2.0
         oslo.context>=0.2.0     # Apache-2.0
         """
     )
     reqs = requirement.parse(content)
     self.assertEqual(set(["oslo.config", "oslo.concurrency", "oslo.context"]), set(reqs.keys()))
Пример #40
0
 def test_match_with_markers(self):
     req = requirement.parse(textwrap.dedent("""
     withmarker>=1.5;python_version=='3.5'
     """))['withmarker'][0][0]
     self.assertTrue(
         check._is_requirement_in_global_reqs(
             req,
             self.global_reqs['withmarker'],
         )
     )
Пример #41
0
 def test_new_item_missing_exclusion(self):
     # If the new item does not include an exclusion that is
     # present in the global list that is OK.
     reqs = [r for r, line in requirement.parse('name>=1.2')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': ''
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         ))
 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))
     )
Пример #43
0
 def test_multiline(self):
     content = '\n'.join(
         ['oslo.config>=1.11.0     # Apache-2.0',
          'oslo.concurrency>=2.3.0 # Apache-2.0',
          'oslo.context>=0.2.0     # Apache-2.0']
     )
     reqs = requirement.parse(content)
     self.assertEqual(
         set(['oslo.config', 'oslo.concurrency', 'oslo.context']),
         set(reqs.keys()),
     )
Пример #44
0
 def test_new_item_matches_py3_allowed_no_py2(self):
     # If the global list has multiple entries for an item but the branch
     # allows python 3 only, then only the py3 entries need to match.
     r_content = textwrap.dedent("""
     name>=1.5;python_version=='3.5'
     """)
     reqs = [r for r, line in requirement.parse(r_content)['name']]
     global_reqs = check.get_global_reqs(
         textwrap.dedent("""
     name>=1.5;python_version=='3.5'
     name>=1.2,!=1.4;python_version=='2.6'
     """))
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
             allow_3_only=True,
         ))
Пример #45
0
 def test_new_item_missing_extra_line(self):
     # If the global list has multiple entries for an item with
     # different "extra" specifiers, the values must all be in the
     # requirements file.
     r_content = textwrap.dedent("""
     name>=1.2,!=1.4;python_version=='2.6'
     """)
     reqs = [r for r, line in requirement.parse(r_content)['name']]
     global_reqs = check.get_global_reqs(
         textwrap.dedent("""
     name>=1.5;python_version=='3.5'
     name>=1.2,!=1.4;python_version=='2.6'
     """))
     self.assertTrue(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         ))
Пример #46
0
 def test_blacklisted_mismatch(self):
     # If the package is blacklisted, it doesn't matter if the
     # version matches.
     reqs = [r for r, line in requirement.parse('name>=1.5')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': 'name>=1.2,!=1.4'
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse('name'),
             global_reqs=global_reqs,
         ))
Пример #47
0
 def test_new_item_lower_min(self):
     # If the new item has a lower minimum value than the global
     # list, that is OK.
     reqs = [r for r, line in requirement.parse('name>=1.1,!=1.4')['name']]
     branch_reqs = check.RequirementsList(
         'testproj',
         {'requirements': {
             'requirements.txt': ''
         }},
     )
     branch_reqs.process(False)
     global_reqs = check.get_global_reqs('name>=1.2,!=1.4')
     self.assertFalse(
         check._validate_one(
             'name',
             reqs=reqs,
             branch_reqs=branch_reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         ))
Пример #48
0
 def test_multiline(self):
     content = textwrap.dedent("""\
         oslo.config>=1.11.0     # Apache-2.0
         oslo.concurrency>=2.3.0 # Apache-2.0
         oslo.context>=0.2.0     # Apache-2.0
         """)
     reqs = requirement.parse(content)
     self.assertEqual(
         set(['oslo.config', 'oslo.concurrency', 'oslo.context']),
         set(reqs.keys()),
     )
Пример #49
0
 def test_requirements_policy_fail(self):
     content = textwrap.dedent("""\
         cffi>=1.1.1,!=1.1.0
         other>=1,>=2,!=1.1.0
         no_lower_bound
         """)
     reqs = requirement.parse(content)
     self.assertEqual([
         'Requirement cffi has a !=1.1.0 specifier that is not >=1.1.1',
         'Requirement no-lower-bound needs a >= specifier',
         'Requirement other has multiple >= specifier'
     ], sorted([x for x in requirement.check_reqs_bounds_policy(reqs)]))
Пример #50
0
def get_global_reqs(content):
    """Return global_reqs structure.

    Parse content and return dict mapping names to sets of Requirement
    objects."

    """
    global_reqs = {}
    parsed = requirement.parse(content)
    for k, entries in parsed.items():
        # Discard the lines: we don't need them.
        global_reqs[k] = set(r for (r, line) in entries)
    return global_reqs
Пример #51
0
def get_global_reqs(content):
    """Return global_reqs structure.

    Parse content and return dict mapping names to sets of Requirement
    objects."

    """
    global_reqs = {}
    parsed = requirement.parse(content)
    for k, entries in parsed.items():
        # Discard the lines: we don't need them.
        global_reqs[k] = set(r for (r, line) in entries)
    return global_reqs
Пример #52
0
 def test_new_item_missing_extra_line(self):
     # If the global list has multiple entries for an item with
     # different "extra" specifiers, the values must all be in the
     # requirements file.
     r_content = textwrap.dedent("""
     name>=1.2,!=1.4;python_version=='2.6'
     """)
     reqs = [
         r
         for r, line in requirement.parse(r_content)['name']
     ]
     global_reqs = check.get_global_reqs(textwrap.dedent("""
     name>=1.5;python_version=='3.5'
     name>=1.2,!=1.4;python_version=='2.6'
     """))
     self.assertTrue(
         check._validate_one(
             'name',
             reqs=reqs,
             blacklist=requirement.parse(''),
             global_reqs=global_reqs,
         )
     )
Пример #53
0
 def test_no_constraints_file(self):
     constraints_content = None
     project_data = {
         'requirements': {'requirements.txt': 'name>=1.2,!=1.4'},
         'lower-constraints.txt': constraints_content,
     }
     head_reqs = check.RequirementsList('testproj', project_data)
     head_reqs.process(False)
     self.assertFalse(
         check.validate_lower_constraints(
             req_list=head_reqs,
             constraints=project_data['lower-constraints.txt'],
             blacklist=requirement.parse(''),
         )
     )
Пример #54
0
 def test_no_constraints_file(self):
     constraints_content = None
     project_data = {
         'requirements': {
             'requirements.txt': 'name>=1.2,!=1.4'
         },
         'lower-constraints.txt': constraints_content,
     }
     head_reqs = check.RequirementsList('testproj', project_data)
     head_reqs.process(False)
     self.assertFalse(
         check.validate_lower_constraints(
             req_list=head_reqs,
             constraints=project_data['lower-constraints.txt'],
             blacklist=requirement.parse(''),
         ))
Пример #55
0
def _extract_reqs(file_name, blacklist=None):
    blacklist = blacklist or {}
    content = open(file_name, 'rt').read()
    reqs = collections.defaultdict(tuple)
    parsed = requirement.parse(content)
    for name, entries in ((name, entries)
                          for (name, entries) in parsed.items()
                          if (name and name not in blacklist)):
        list_reqs = [r for (r, line) in entries]
        # Strip the comments out before checking if there are duplicates
        list_reqs_stripped = [r._replace(comment='') for r in list_reqs]
        if len(list_reqs_stripped) != len(set(list_reqs_stripped)):
            print('Requirements file %s has duplicate entries for package '
                  '"%s: %r' % (file_name, name, list_reqs))
        reqs[name] = list_reqs
    return reqs
Пример #56
0
 def test_unparseable_line(self):
     global_content = textwrap.dedent("""\
         foo
         """)
     project_content = textwrap.dedent("""\
         foo
         -e https://git.openstack.org/openstack/neutron.git#egg=neutron
         """)
     global_reqs = requirement.parse(global_content)
     project_reqs = list(requirement.to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     n = '-e https://git.openstack.org/openstack/neutron.git#egg=neutron'
     self.assertEqual(requirement.Requirements([
         requirement.Requirement('foo', '', '', '', ''),
         requirement.Requirement('', '', '', '', n)]),
         reqs)
Пример #57
0
 def extract_reqs(self, content, strict):
     reqs = collections.defaultdict(set)
     parsed = requirement.parse(content)
     for name, entries in parsed.items():
         if not name:
             # Comments and other unprocessed lines
             continue
         list_reqs = [r for (r, line) in entries]
         # Strip the comments out before checking if there are duplicates
         list_reqs_stripped = [r._replace(comment='') for r in list_reqs]
         if strict and len(list_reqs_stripped) != len(
                 set(list_reqs_stripped)):
             print("Requirements file has duplicate entries "
                   "for package %s : %r." % (name, list_reqs))
             self.failed = True
         reqs[name].update(list_reqs)
     return reqs
Пример #58
0
 def test_constrained_version_excluded(self):
     constraints_content = textwrap.dedent("""
     name==1.2
     """)
     project_data = {
         'requirements': {'requirements.txt': 'name>=1.1,!=1.2'},
         'lower-constraints.txt': constraints_content,
     }
     head_reqs = check.RequirementsList('testproj', project_data)
     head_reqs.process(False)
     self.assertTrue(
         check.validate_lower_constraints(
             req_list=head_reqs,
             constraints=project_data['lower-constraints.txt'],
             blacklist=requirement.parse(''),
         )
     )
Пример #59
0
 def test_unparseable_line(self):
     global_content = textwrap.dedent("""\
         foo
         """)
     project_content = textwrap.dedent("""\
         foo
         -e https://git.openstack.org/openstack/neutron.git#egg=neutron
         """)
     global_reqs = requirement.parse(global_content)
     project_reqs = list(requirement.to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     n = '-e https://git.openstack.org/openstack/neutron.git#egg=neutron'
     self.assertEqual(requirement.Requirements([
         requirement.Requirement('foo', '', '', '', ''),
         requirement.Requirement('', '', '', '', n)]),
         reqs)