Example #1
0
 def test_location(self):
     reqs = requirement.to_content(
         requirement.Requirements(
             [requirement.Requirement("foo", "file://foo", "", "python_version=='2.7'", "# BSD")]
         )
     )
     self.assertEqual("".join(requirement._REQS_HEADER + ["file://foo#egg=foo;python_version=='2.7' # BSD\n"]), reqs)
Example #2
0
def merge_setup_cfg(old_content, new_extras):
    # This is ugly. All the existing libraries handle setup.cfg's poorly.
    prefix, extras, suffix = _extras_compiled(old_content).ini()
    out_extras = []
    if extras is not None:
        for extra in extras:
            if type(extra) is _Comment:
                out_extras.append(extra)
            elif type(extra) is _Extra:
                if extra.name not in new_extras:
                    out_extras.append(extra)
                    continue
                e = _Extra(
                    extra.name,
                    requirement.to_content(
                        new_extras[extra.name], ':', '  ', False))
                out_extras.append(e)
            else:
                raise TypeError('unknown type %r' % extra)
    if out_extras:
        extras_str = ['[extras]\n']
        for extra in out_extras:
            if type(extra) is _Comment:
                extras_str.append(extra.line)
            else:
                extras_str.append(extra.name + ' =')
                extras_str.append(extra.content)
        if suffix:
            extras_str.append('\n')
        extras_str = ''.join(extras_str)
    else:
        extras_str = ''
    return prefix + extras_str + suffix
Example #3
0
 def test_location(self):
     reqs = requirement.to_content(requirement.Requirements(
         [requirement.Requirement(
          'foo', 'file://foo', '', "python_version=='2.7'", '# BSD')]))
     self.assertEqual(
         ''.join(requirement._REQS_HEADER
                 + ["file://foo#egg=foo;python_version=='2.7' # BSD\n"]),
         reqs)
Example #4
0
 def test_smoke(self):
     reqs = requirement.to_content(requirement.Requirements(
         [requirement.Requirement(
          'foo', '', '<=1', "python_version=='2.7'", '# BSD')]),
         marker_sep='!')
     self.assertEqual(
         ''.join(requirement._REQS_HEADER
                 + ["foo<=1!python_version=='2.7' # BSD\n"]),
         reqs)
Example #5
0
def main(argv=None, stdout=None):
    parser = optparse.OptionParser(
        usage="%prog [options] constraintpath name replacement",
        epilog=textwrap.dedent("""\
            Replaces any entries of "name" in the constraints file with
            "replacement". If "name" is not present, it is added to the end of
            the file. If "replacement" is missing or empty, remove "name" from
            the file.
            """))
    options, args = parser.parse_args(argv)
    if stdout is None:
        stdout = sys.stdout
    _validate_options(options, args)
    args = args + [""]
    content = open(args[0], 'rt').read()
    reqs = requirement.parse(content, permit_urls=True)
    out_reqs = edit(reqs, args[1], args[2])
    out = requirement.to_content(out_reqs, prefix=False)
    with open(args[0] + '.tmp', 'wt') as f:
        f.write(out)
    os.rename(args[0] + '.tmp', args[0])
    return 0
Example #6
0
def _copy_requires(
        suffix, softupdate, hacking, proj, global_reqs, non_std_reqs,
        blacklist={}):
    """Copy requirements files."""
    actions = []
    for source, content in sorted(proj['requirements'].items()):
        dest_path = os.path.join(proj['root'], source)
        # this is specifically for global-requirements gate jobs so we don't
        # modify the git tree
        if suffix:
            dest_path = "%s.%s" % (dest_path, suffix)
            dest_name = "%s.%s" % (source, suffix)
        else:
            dest_name = source
        dest_sequence = list(requirement.to_reqs(content))
        actions.append(project.Verbose("Syncing %s" % dest_path))
        _actions, reqs = _sync_requirements_file(
            global_reqs, dest_sequence, dest_path, softupdate, hacking,
            non_std_reqs, blacklist)
        actions.extend(_actions)
        actions.append(project.File(dest_name, requirement.to_content(reqs)))
    extras = project.extras(proj)
    output_extras = {}
    for extra, content in sorted(extras.items()):
        dest_name = 'extra-%s' % extra
        dest_path = "%s[%s]" % (proj['root'], extra)
        dest_sequence = list(requirement.to_reqs(content))
        actions.append(project.Verbose("Syncing extra [%s]" % extra))
        _actions, reqs = _sync_requirements_file(
            global_reqs, dest_sequence, dest_path, softupdate, hacking,
            non_std_reqs, blacklist)
        actions.extend(_actions)
        output_extras[extra] = reqs
    dest_path = 'setup.cfg'
    if suffix:
        dest_path = "%s.%s" % (dest_path, suffix)
    actions.append(project.File(
        dest_path, project.merge_setup_cfg(proj['setup.cfg'], output_extras)))
    return actions
Example #7
0
 def test_smoke(self):
     reqs = requirement.to_content(
         requirement.Requirements([requirement.Requirement("foo", "", "<=1", "python_version=='2.7'", "# BSD")]),
         marker_sep="!",
     )
     self.assertEqual("".join(requirement._REQS_HEADER + ["foo<=1!python_version=='2.7' # BSD\n"]), reqs)