Beispiel #1
0
 def test_does_not_parse(self):
     try:
         requirement.parse_line(self.line)
     except (pkg_resources.RequirementParseError,
             pkg_resources_reqs.InvalidRequirement):
         pass
     else:
         self.fail('No exception triggered')
 def test_constraints_format(self):
     errors = 0
     constraints_content = open("upper-constraints.txt", "rt").read()
     for n, line in enumerate(constraints_content.splitlines(), 1):
         c = requirement.parse_line(line)
         spec = c.specifiers
         if not spec.startswith("==="):
             print('Invalid constraint line %d %r, does not have 3 "="' % (n, line))
             errors += 1
     if errors:
         self.fail("Encountered errors parsing constraints.txt")
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(
        description="Normalize requirements files")
    parser.add_argument('requirements', help='requirements file input')
    args = parser.parse_args()
    with open(args.requirements) as f:
        requirements = [line.strip() for line in f.readlines()]

    for line in requirements:
        req = requirement.parse_line(line)
        print(req.to_line(comment_prefix='  ', sort_specifiers=True), end='')
def main():
    parser = argparse.ArgumentParser(
        description="Normalize requirements files")
    parser.add_argument('requirements', help='requirements file input')
    args = parser.parse_args()
    with open(args.requirements) as f:
        requirements = [line.strip() for line in f.readlines()]

    for line in requirements:
        req = requirement.parse_line(line)
        print(req.to_line(comment_prefix='  ',
                          sort_specifiers=True), end='')
def main():
    parser = argparse.ArgumentParser(
        description="Normalize requirements files")
    parser.add_argument('requirements', help='requirements file input')
    parser.add_argument('-s', '--save', action='store_true', default=False,
                        help=('save normalized requirements '
                              'file instead of displaying it'))
    args = parser.parse_args()
    with open(args.requirements) as f:
        requirements = [line.strip() for line in f.readlines()]

    normed_reqs = ""
    for line in requirements:
        req = requirement.parse_line(line)
        normed_req = req.to_line(comment_prefix='  ', sort_specifiers=True)
        normed_reqs += normed_req

    if args.save:
        write_requirements_file(args.requirements, normed_reqs)
    else:
        print(normed_reqs, end='')
 def test_does_not_parse(self):
     with testtools.ExpectedException(InvalidRequirement):
         requirement.parse_line(self.line)
 def test_parse(self):
     parsed = requirement.parse_line(
         self.line, permit_urls=getattr(self, 'permit_urls', False))
     self.assertEqual(self.req, parsed)
 def test_does_not_parse(self):
     with testtools.ExpectedException(pkg_resources.RequirementParseError):
         requirement.parse_line(self.line)
Beispiel #9
0
 def test_parse(self):
     parsed = requirement.parse_line(self.line,
                                     permit_urls=getattr(
                                         self, 'permit_urls', False))
     self.assertEqual(self.req, parsed)
Beispiel #10
0
 def test_does_not_parse(self):
     with testtools.ExpectedException(InvalidRequirement):
         requirement.parse_line(self.line)
Beispiel #11
0
 def test_does_not_parse(self):
     with testtools.ExpectedException(pkg_resources.RequirementParseError):
         requirement.parse_line(self.line)
Beispiel #12
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'global_requirements',
        default='global-requirements.txt',
        help='path to the global-requirements.txt file',
    )
    parser.add_argument(
        'upper_constraints',
        default='upper-constraints.txt',
        help='path to the upper-constraints.txt file',
    )
    parser.add_argument(
        'blacklist',
        default='blacklist.txt',
        help='path to the blacklist.txt file',
    )
    args = parser.parse_args()

    error_count = 0

    # Check the format of the constraints file.
    print('\nChecking %s' % args.upper_constraints)
    constraints_txt = read_requirements_file(args.upper_constraints)
    for msg in constraints.check_format(constraints_txt):
        print(msg)
        error_count += 1

    # Check that the constraints and requirements are compatible.
    print('\nChecking %s' % args.global_requirements)
    global_reqs = read_requirements_file(args.global_requirements)
    for msg in constraints.check_compatible(global_reqs, constraints_txt):
        print(msg)
        error_count += 1

    # Check requirements to satisfy policy.
    print('\nChecking requirements on %s' % args.global_requirements)
    for msg in requirement.check_reqs_bounds_policy(global_reqs):
        print(msg)
        error_count += 1

    # Check that global requirements are uniformly formatted
    print('\nValidating uniform formatting on %s' % args.global_requirements)
    with open(args.global_requirements, 'rt') as f:
        for line in f:
            if line == '\n':
                continue
            req = requirement.parse_line(line)
            normed_req = req.to_line(comment_prefix='  ', sort_specifiers=True)
            if line.rstrip() != normed_req.rstrip():
                print("-%s\n+%s" % (line.rstrip(), normed_req.rstrip()))
                error_count += 1

    # Check that all of the items in the global-requirements list
    # appear in exactly one of the constraints file or the blacklist.
    print('\nChecking %s' % args.blacklist)
    blacklist = read_requirements_file(args.blacklist)
    for msg in constraints.check_blacklist_coverage(
            global_reqs, constraints_txt, blacklist,
            os.path.basename(args.upper_constraints)):
        print(msg)
        error_count += 1

    return 1 if error_count else 0
Beispiel #13
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'global_requirements',
        default='global-requirements.txt',
        help='path to the global-requirements.txt file',
    )
    parser.add_argument(
        'upper_constraints',
        default='upper-constraints.txt',
        help='path to the upper-constraints.txt file',
    )
    parser.add_argument(
        'blacklist',
        default='blacklist.txt',
        help='path to the blacklist.txt file',
    )
    args = parser.parse_args()

    error_count = 0

    # Check the format of the constraints file.
    print('\nChecking %s' % args.upper_constraints)
    constraints_txt = read_requirements_file(args.upper_constraints)
    for msg in constraints.check_format(constraints_txt):
        print(msg)
        error_count += 1

    # Check that the constraints and requirements are compatible.
    print('\nChecking %s' % args.global_requirements)
    global_reqs = read_requirements_file(args.global_requirements)
    for msg in constraints.check_compatible(global_reqs, constraints_txt):
        print(msg)
        error_count += 1

    # Check requirements to satisfy policy.
    print('\nChecking requirements on %s' % args.global_requirements)
    for msg in requirement.check_reqs_bounds_policy(global_reqs):
        print(msg)
        error_count += 1

    # Check that global requirements are uniformly formatted
    print('\nValidating uniform formatting on %s' % args.global_requirements)
    with open(args.global_requirements, 'rt') as f:
        for line in f:
            if line == '\n':
                continue
            req = requirement.parse_line(line)
            normed_req = req.to_line(comment_prefix='  ', sort_specifiers=True)
            if line.rstrip() != normed_req.rstrip():
                print("-%s\n+%s" % (line.rstrip(), normed_req.rstrip()))
                error_count += 1

    # Check that all of the items in the global-requirements list
    # appear in exactly one of the constraints file or the blacklist.
    print('\nChecking %s' % args.blacklist)
    blacklist = read_requirements_file(args.blacklist)
    for msg in constraints.check_blacklist_coverage(
            global_reqs, constraints_txt, blacklist,
            os.path.basename(args.upper_constraints)):
        print(msg)
        error_count += 1

    return 1 if error_count else 0