Ejemplo n.º 1
0
def generate_requirements(
    extras_require: dict[str, list[str]]
) -> Iterator[tuple[str, str]]:
    """
    Convert requirements from a setup()-style dictionary to
    ('Requires-Dist', 'requirement') and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    """
    for extra, depends in extras_require.items():
        condition = ""
        extra = extra or ""
        if ":" in extra:  # setuptools extra:condition syntax
            extra, condition = extra.split(":", 1)

        extra = safe_extra(extra)
        if extra:
            yield "Provides-Extra", extra
            if condition:
                condition = "(" + condition + ") and "
            condition += "extra == '%s'" % extra

        if condition:
            condition = " ; " + condition

        for new_req in convert_requirements(depends):
            yield "Requires-Dist", new_req + condition
Ejemplo n.º 2
0
def generate_requirements(extras_require):
    """
    Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
    and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    """
    requirements = set()
    for extra, depends in extras_require.items():
        condition = ''
        if extra and ':' in extra:  # setuptools extra:condition syntax
            extra, condition = extra.split(':', 1)
            extra = pkg_resources.safe_extra(extra)

        if extra:
            requirements.add(('Provides-Extra', extra))
            if condition:
                condition = "(" + condition + ") and "
            condition += "extra == '%s'" % extra

        if condition:
            condition = '; ' + condition

        for new_req in convert_requirements(depends):
            requirements.add(('Requires-Dist', new_req + condition))

    return requirements
Ejemplo n.º 3
0
def generate_requirements(extras_require):
    """
    Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
    and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    """
    for extra, depends in extras_require.items():
        condition = ''
        extra = extra or ''
        if ':' in extra:  # setuptools extra:condition syntax
            extra, condition = extra.split(':', 1)

        extra = pkg_resources.safe_extra(extra)
        if extra:
            yield 'Provides-Extra', extra
            if condition:
                condition = "(" + condition + ") and "
            condition += "extra == '%s'" % extra

        if condition:
            condition = '; ' + condition

        for new_req in convert_requirements(depends):
            yield 'Requires-Dist', new_req + condition
Ejemplo n.º 4
0
def generate_requirements(extras_require):
    """
    Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
    and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    """
    for extra, depends in extras_require.items():
        condition = ""
        extra = extra or ""
        if ":" in extra:  # setuptools extra:condition syntax
            extra, condition = extra.split(":", 1)

        extra = safe_extra(extra)
        if extra:
            yield "Provides-Extra", extra
            if condition:
                condition = "(" + condition + ") and "
            condition += "extra == '%s'" % extra

        for dependency in depends:
            new_req = Requirement(dependency)
            if condition:
                if new_req.marker:
                    new_req.marker = "(%s) and %s" % (new_req.marker,
                                                      condition)
                else:
                    new_req.marker = condition
            yield "Requires-Dist", str(new_req)
Ejemplo n.º 5
0
def dep_map(requires_txt):
    """Parse dependency map. From setuptools."""
    dm = collections.OrderedDict({None: []})
    for extra, reqs in split_sections(requires_txt):
        if extra: extra = safe_extra(extra)
        dm.setdefault(extra, []).extend(parse_requirements(reqs))
    return dm
Ejemplo n.º 6
0
def strip_extras(resolvable_string):
  match = _EXTRAS_PATTERN.match(resolvable_string)
  if match:
    resolvable_string, extras = match.groupdict()['main'], match.groupdict()['extras']
    extras = [safe_extra(extra.strip()) for extra in extras.split(',')]
  else:
    extras = []
  return resolvable_string, extras
Ejemplo n.º 7
0
    def __init__(self, req, comes_from, source_dir=None, editable=False,
                 link=None, update=True, pycompile=True, markers=None,
                 isolated=False, options=None, wheel_cache=None,
                 constraint=False, extras=()):
        assert req is None or isinstance(req, Requirement), req
        self.req = req
        self.comes_from = comes_from
        self.constraint = constraint
        if source_dir is not None:
            self.source_dir = os.path.normpath(os.path.abspath(source_dir))
        else:
            self.source_dir = None
        self.editable = editable

        self._wheel_cache = wheel_cache
        if link is not None:
            self.link = self.original_link = link
        else:
            self.link = self.original_link = req and req.url and Link(req.url)

        if extras:
            self.extras = extras
        elif req:
            self.extras = {
                pkg_resources.safe_extra(extra) for extra in req.extras
            }
        else:
            self.extras = set()
        if markers is not None:
            self.markers = markers
        else:
            self.markers = req and req.marker
        self._egg_info_path = None
        # This holds the pkg_resources.Distribution object if this requirement
        # is already available:
        self.satisfied_by = None
        # True if the editable should be updated:
        self.update = update
        # Set to True after successful installation
        self.install_succeeded = None
        # UninstallPathSet of uninstalled distribution (for possible rollback)
        self.uninstalled_pathset = None
        self.use_user_site = False
        self.target_dir = None
        self.options = options if options else {}
        self.pycompile = pycompile
        # Set to True after successful preparation of this requirement
        self.prepared = False

        self.isolated = isolated
Ejemplo n.º 8
0
        def process(requirement_sets, extras, environment):
            for requirements in requirement_sets:
                if 'extra' in requirements:
                    if safe_extra(requirements['extra']) not in extras:
                        continue

                if 'environment' in requirements:
                    marker = Marker(requirements['environment'])
                    if not marker.evaluate(environment):
                        continue

                for req in requirements['requires']:
                    req = utils.parse_requirement(req)
                    req.extras = extras
                    yield Requirement(str(req))
Ejemplo n.º 9
0
        def process(requirement_sets, extras, environment):
            for requirements in requirement_sets:
                if 'extra' in requirements:
                    if safe_extra(requirements['extra']) not in extras:
                        continue

                if 'environment' in requirements:
                    marker = Marker(requirements['environment'])
                    if not marker.evaluate(environment):
                        continue

                for req in requirements['requires']:
                    req = utils.parse_requirement(req)
                    req.extras = extras
                    yield Requirement(str(req))
Ejemplo n.º 10
0
    def add_requirement(self, req, extra="run"):

        # cast to Requirement
        if not isinstance(req, Requirement):
            try:
                req = Requirement.from_line(req)
            except (pkg_resources.RequirementParseError, ValueError) as exc:
                log.warning("%r %r add %r raised %r", self, extra, req, exc)
                return

        if not req.is_named:
            log.warning("%r ignoring unnamed %r", self, req)
            return

        # skip out for implicit requirements
        if req.name in self.IMPLICIT_PACKAGES:
            return

        # check existing requirement
        for ereq in self.requires[extra] \
                | (extra != "run" and self.requires["run"] or set()):
            if ereq.normalized_name == req.normalized_name:
                return

        if extra != "run":
            if ":" in extra:  # setuptools extra:condition syntax
                extra, condition = extra.split(":", 1)
                if not Marker(condition).evaluate():
                    return
            if extra:
                extra = pkg_resources.safe_extra(extra)
                self.provides_extra.add(extra)
                req.markers = req.req.markers = "extra == '%s'" % extra

        self.requires_dist.add(str(req))
        del self.requires
        return req