當前位置: 首頁>>代碼示例>>Python>>正文


Python packaging.markers方法代碼示例

本文整理匯總了Python中packaging.markers方法的典型用法代碼示例。如果您正苦於以下問題:Python packaging.markers方法的具體用法?Python packaging.markers怎麽用?Python packaging.markers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在packaging的用法示例。


在下文中一共展示了packaging.markers方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _filter_extras

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def _filter_extras(dm):
        """
        Given a mapping of extras to dependencies, strip off
        environment markers and filter out any dependencies
        not matching the markers.
        """
        for extra in list(filter(None, dm)):
            new_extra = extra
            reqs = dm.pop(extra)
            new_extra, _, marker = extra.partition(':')
            fails_marker = marker and (
                invalid_marker(marker)
                or not evaluate_marker(marker)
            )
            if fails_marker:
                reqs = []
            new_extra = safe_extra(new_extra) or None

            dm.setdefault(new_extra, []).extend(reqs)
        return dm 
開發者ID:pypa,項目名稱:pkg_resources,代碼行數:22,代碼來源:__init__.py

示例2: __str__

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def __str__(self):
        pyspecs = set()
        markerset = set()
        for m in self.markerset:
            marker_specs = pyspec_from_markers(packaging.markers.Marker(m))
            if marker_specs:
                pyspecs.add(marker_specs)
            else:
                markerset.add(m)
        if pyspecs:
            self.pyspecset._specs &= pyspecs
            self.markerset = frozenset(markerset)
        return " and ".join(dedup_markers(itertools.chain(
            # Make sure to always use the same quotes so we can dedup properly.
            (
                "{0}".format(ms) if " or " in ms else ms
                for ms in (str(m).replace('"', "'") for m in self.markerset)
            ),
            (
                "python_version {0[0]} '{0[1]}'".format(spec)
                for spec in cleanup_pyspecs(self.pyspecset)
            ),
        ))) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:25,代碼來源:metadata.py

示例3: _build_metasets

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def _build_metasets(dependencies, pythons, key, trace, all_metasets):
    all_parent_metasets = []
    for route in trace:
        parent = route[-1]
        try:
            parent_metasets = all_metasets[parent]
        except KeyError:    # Parent not calculated yet. Wait for it.
            return
        all_parent_metasets.append((parent, parent_metasets))

    metaset_iters = []
    for parent, parent_metasets in all_parent_metasets:
        r = dependencies[parent][key]
        python = pythons[key]
        metaset = (
            get_without_extra(r.markers),
            packaging.specifiers.SpecifierSet(python),
        )
        metaset_iters.append(
            parent_metaset | metaset
            for parent_metaset in parent_metasets
        )
    return list(itertools.chain.from_iterable(metaset_iters)) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:25,代碼來源:metadata.py

示例4: set_metadata

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def set_metadata(candidates, traces, dependencies, pythons):
    """Add "metadata" to candidates based on the dependency tree.

    Metadata for a candidate includes markers and a specifier for Python
    version requirements.

    :param candidates: A key-candidate mapping. Candidates in the mapping will
        have their markers set.
    :param traces: A graph trace (produced by `traces.trace_graph`) providing
        information about dependency relationships between candidates.
    :param dependencies: A key-collection mapping containing what dependencies
        each candidate in `candidates` requested.
    :param pythons: A key-str mapping containing Requires-Python information
        of each candidate.

    Keys in mappings and entries in the trace are identifiers of a package, as
    implemented by the `identify` method of the resolver's provider.

    The candidates are modified in-place.
    """
    metasets_mapping = _calculate_metasets_mapping(
        dependencies, pythons, copy.deepcopy(traces),
    )
    for key, candidate in candidates.items():
        candidate.markers = _format_metasets(metasets_mapping[key]) 
開發者ID:sarugaku,項目名稱:passa,代碼行數:27,代碼來源:metadata.py

示例5: markers_pass

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def markers_pass(self, req, extras=None):
        """
        Evaluate markers for req against each extra that
        demanded it.

        Return False if the req has a marker and fails
        evaluation. Otherwise, return True.
        """
        extra_evals = (
            req.marker.evaluate({'extra': extra})
            for extra in self.get(req, ()) + (extras or (None,))
        )
        return not req.marker or any(extra_evals) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:15,代碼來源:__init__.py

示例6: evaluate_marker

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def evaluate_marker(text, extra=None):
    """
    Evaluate a PEP 508 environment marker.
    Return a boolean indicating the marker result in this environment.
    Raise SyntaxError if marker is invalid.

    This implementation uses the 'pyparsing' module.
    """
    try:
        marker = packaging.markers.Marker(text)
        return marker.evaluate()
    except packaging.markers.InvalidMarker as e:
        raise SyntaxError(e) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:15,代碼來源:__init__.py

示例7: _are_pipfile_entries_equal

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def _are_pipfile_entries_equal(a, b):
    a = {k: v for k, v in a.items() if k not in ("markers", "hashes", "hash")}
    b = {k: v for k, v in b.items() if k not in ("markers", "hashes", "hash")}
    if a != b:
        return False
    try:
        marker_eval_a = packaging.markers.Marker(a["markers"]).evaluate()
    except (AttributeError, KeyError, TypeError, ValueError):
        marker_eval_a = True
    try:
        marker_eval_b = packaging.markers.Marker(b["markers"]).evaluate()
    except (AttributeError, KeyError, TypeError, ValueError):
        marker_eval_b = True
    return marker_eval_a == marker_eval_b 
開發者ID:pypa,項目名稱:pipenv,代碼行數:16,代碼來源:project.py

示例8: _format_metasets

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def _format_metasets(metasets):
    # If there is an unconditional route, this needs to be unconditional.
    if not metasets or not all(metasets):
        return None

    # This extra str(Marker()) call helps simplify the expression.
    return str(packaging.markers.Marker(" or ".join(
        "{0}".format(s) if " and " in s else s
        for s in dedup_markers(str(metaset) for metaset in metasets
        if metaset)
    ))) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:13,代碼來源:metadata.py

示例9: format_full_version

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def format_full_version(info):
    version = "{0.major}.{0.minor}.{0.micro}".format(info)
    kind = info.releaselevel
    if kind != "final":
        version += kind[0] + str(info.serial)
    return version


# cribbed from packaging.markers to avoid a runtime dependency here 
開發者ID:wimglenn,項目名稱:johnnydep,代碼行數:11,代碼來源:env_check.py

示例10: sync

# 需要導入模塊: import packaging [as 別名]
# 或者: from packaging import markers [as 別名]
def sync(self):
        groupcoll = _group_installed_names(self.packages)

        installed = set()
        updated = set()
        cleaned = set()

        # TODO: Show a prompt to confirm cleaning. We will need to implement a
        # reporter pattern for this as well.
        if self.clean_unneeded:
            names = _clean(groupcoll.unneeded)
            cleaned.update(names)

        # TODO: Specify installation order? (pypa/pipenv#2274)
        installers = []
        for name, package in self.packages.items():
            r = requirementslib.Requirement.from_pipfile(name, package)
            name = r.normalized_name
            if name in groupcoll.uptodate:
                continue
            markers = r.markers
            if markers and not packaging.markers.Marker(markers).evaluate():
                continue
            r.markers = None
            if r.editable:
                installer = EditableInstaller(r)
            else:
                installer = WheelInstaller(r, self.sources, self.paths)
            try:
                installer.prepare()
            except Exception as e:
                if os.environ.get("PASSA_NO_SUPPRESS_EXCEPTIONS"):
                    raise
                print("failed to prepare {0!r}: {1}".format(
                    r.as_line(include_hashes=False), e,
                ))
            else:
                installers.append((name, installer))

        for name, installer in installers:
            if name in groupcoll.outdated:
                name_to_remove = name
            else:
                name_to_remove = None
            try:
                with _remove_package(name_to_remove):
                    installer.install()
            except Exception as e:
                if os.environ.get("PASSA_NO_SUPPRESS_EXCEPTIONS"):
                    raise
                print("failed to install {0!r}: {1}".format(
                    r.as_line(include_hashes=False), e,
                ))
                continue
            if name in groupcoll.outdated or name in groupcoll.noremove:
                updated.add(name)
            else:
                installed.add(name)

        return installed, updated, cleaned 
開發者ID:pypa,項目名稱:pipenv,代碼行數:62,代碼來源:synchronizers.py


注:本文中的packaging.markers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。