How to use the packaging.markers.Marker function in packaging

To help you get started, we’ve selected a few packaging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / packaging / tests / test_markers.py View on Github external
def test_evaluate_setuptools_legacy_markers(self):
        marker_string = "python_implementation=='Jython'"
        args = [{"platform_python_implementation": "CPython"}]
        assert Marker(marker_string).evaluate(*args) is False
github sarugaku / requirementslib / tests / unit / test_markers.py View on Github external
        (Marker("extra == 'security' or extra == 'socks'"), True, False),
        (Marker("extra == 'security' and python_version >= '2.7'"), True, True),
        (
            Marker(
                "python_version >= '2.7' and python_version not in '3.0.*, 3.1.*, 3.2.*, 3.3.*'"
            ),
            False,
            True,
        ),
    ],
)
def test_contains_extras_or_pyversions(marker, contains_extras, contains_pyversion):
    assert requirementslib.models.markers.contains_extra(marker) is contains_extras
    assert requirementslib.models.markers.contains_pyversion(marker) is contains_pyversion
github sarugaku / requirementslib / tests / unit / test_markers.py View on Github external
        (Marker("extra == 'security' and os_name == 'nt'"), {"security"}),
        (Marker("os_name == 'security' and python_version >= '2.7'"), set()),
    ],
)
def test_get_extras(marker, extras):
    assert requirementslib.models.markers.get_contained_extras(marker) == extras
github pypa / packaging / tests / test_markers.py View on Github external
def test_evaluate_pep345_markers(self, marker_string, environment, expected):
        args = [] if environment is None else [environment]
        assert Marker(marker_string).evaluate(*args) == expected
github pypa / pipenv / pipenv / vendor / requirementslib / models / markers.py View on Github external
marker_parts = getattr(marker, "_markers", [])
                if marker_parts[0][0].value == "python_version":
                    side_specs |= set(get_specset(marker_parts))
                else:
                    side_markers.add(str(marker))
            side_spec_list.append(side_specs)
            side_markers_list.append(side_markers)
        if op == "and":
            # When we are "and"-ing things together, it probably makes the most sense
            # to reduce them here into a single PySpec instance
            specs = reduce(lambda x, y: set(x) | set(y), side_spec_list)
            markers = reduce(lambda x, y: set(x) | set(y), side_markers_list)
            if not specs and not markers:
                return specset, finalized_marker
            if markers and isinstance(markers, (tuple, list, Set)):
                finalized_marker = Marker(" and ".join([m for m in markers if m]))
            elif markers:
                finalized_marker = str(markers)
            specset._specs = frozenset(specs)
            return specset, finalized_marker
        # Actually when we "or" things as well we can also just turn them into a reduced
        # set using this logic now
        sides = reduce(lambda x, y: set(x) & set(y), side_spec_list)
        finalized_marker = " or ".join(
            [normalize_marker_str(m) for m in side_markers_list]
        )
        specset._specs = frozenset(sorted(sides))
        return specset, finalized_marker
    else:
        # At the tip of the tree we are dealing with strings all around and they just need
        # to be smashed together
        specs = set()
github ryfeus / lambda-packs / Skimage_numpy / source / pkg_resources / __init__.py View on Github external
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)
github sarugaku / passa / src / passa / models / metadata.py View on Github external
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)
github pypa / pipenv / pipenv / vendor / passa / models / metadata.py View on Github external
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)
github pypa / pipenv / pipenv / vendor / requirementslib / models / markers.py View on Github external
def make_marker(cls, marker_string):
        try:
            marker = Marker(marker_string)
        except InvalidMarker:
            raise RequirementError(
                "Invalid requirement: Invalid marker %r" % marker_string
            )
        return marker