How to use the packaging.specifiers.SpecifierSet 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_specifiers.py View on Github external
assert result == SpecifierSet(expected)
        assert result.prereleases

        result = SpecifierSet(left, prereleases=False) & SpecifierSet(right)
        assert result == SpecifierSet(expected)
        assert not result.prereleases

        result = SpecifierSet(left) & SpecifierSet(right, prereleases=True)
        assert result == SpecifierSet(expected)
        assert result.prereleases

        result = SpecifierSet(left) & SpecifierSet(right, prereleases=False)
        assert result == SpecifierSet(expected)
        assert not result.prereleases

        result = SpecifierSet(left, prereleases=True) & SpecifierSet(
            right, prereleases=True
        )
        assert result == SpecifierSet(expected)
        assert result.prereleases

        result = SpecifierSet(left, prereleases=False) & SpecifierSet(
            right, prereleases=False
        )
        assert result == SpecifierSet(expected)
        assert not result.prereleases

        with pytest.raises(ValueError):
            result = SpecifierSet(left, prereleases=True) & SpecifierSet(
                right, prereleases=False
            )
github misakar / mana / test / flaskapp / venv / lib / python2.7 / site-packages / pkg_resources / __init__.py View on Github external
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        self.specifier = packaging.specifiers.SpecifierSet(
            ",".join(["".join([x, y]) for x, y in specs])
        )
        self.specs = specs
        self.extras = tuple(map(safe_extra, extras))
        self.hashCmp = (
            self.key,
            self.specifier,
            frozenset(self.extras),
        )
        self.__hash = hash(self.hashCmp)
github pypa / packaging / tests / test_specifiers.py View on Github external
def test_specifiers_combine(self, left, right, expected):
        result = SpecifierSet(left) & SpecifierSet(right)
        assert result == SpecifierSet(expected)

        result = SpecifierSet(left) & right
        assert result == SpecifierSet(expected)

        result = SpecifierSet(left, prereleases=True) & SpecifierSet(right)
        assert result == SpecifierSet(expected)
        assert result.prereleases

        result = SpecifierSet(left, prereleases=False) & SpecifierSet(right)
        assert result == SpecifierSet(expected)
        assert not result.prereleases

        result = SpecifierSet(left) & SpecifierSet(right, prereleases=True)
        assert result == SpecifierSet(expected)
        assert result.prereleases
github pypa / packaging / tests / test_specifiers.py View on Github external
def test_comparison_canonicalizes(self, left, right):
        assert SpecifierSet(left) == SpecifierSet(right)
        assert left == SpecifierSet(right)
        assert SpecifierSet(left) == right
github pypa / warehouse / warehouse / forklift / legacy.py View on Github external
def _validate_pep440_specifier(specifier):
    try:
        packaging.specifiers.SpecifierSet(specifier)
    except packaging.specifiers.InvalidSpecifier:
        raise wtforms.validators.ValidationError(
            "Invalid specifier in requirement."
        ) from None
github jimporter / bfg9000 / bfg9000 / backends / ninja / rules.py View on Github external
def command_build(buildfile, output, inputs=None, implicit=None,
                  order_only=None, commands=None, env=None):
    # XXX: Only make some command builds use the console pool?
    extra_kwargs = {}
    if version in SpecifierSet('>=1.5'):
        extra_kwargs['pool'] = 'console'

    if not buildfile.has_rule('command'):
        buildfile.rule(name='command', command=var('cmd'), **extra_kwargs)
    if not buildfile.has_build('PHONY'):
        buildfile.build(output='PHONY', rule='phony')

    buildfile.build(
        output=output,
        rule='command',
        inputs=inputs,
        implicit=iterutils.listify(implicit) + ['PHONY'],
        order_only=order_only,
        variables={'cmd': Commands(commands, env)}
    )
github facebook / buck / third-party / py / setuptools / pkg_resources / __init__.py View on Github external
def __init__(self, project_name, specs, extras):
        """DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
        self.unsafe_name, project_name = project_name, safe_name(project_name)
        self.project_name, self.key = project_name, project_name.lower()
        self.specifier = packaging.specifiers.SpecifierSet(
            ",".join(["".join([x, y]) for x, y in specs])
        )
        self.specs = specs
        self.extras = tuple(map(safe_extra, extras))
        self.hashCmp = (
            self.key,
            self.specifier,
            frozenset(self.extras),
        )
        self.__hash = hash(self.hashCmp)
github artsy / hokusai / hokusai / lib / config.py View on Github external
def _check_required_version(self, required_version, target_version):
    if required_version is None:
      return True
    try:
      match_versions = SpecifierSet(required_version)
    except InvalidSpecifier:
      raise HokusaiError("Could not parse '%s' as a valid version specifier. See https://www.python.org/dev/peps/pep-0440/#version-specifiers" % required_version)
    try:
      compare_version = Version(target_version)
    except InvalidVersion:
      raise HokusaiError("Could not parse '%s' as a valid version identifier. See https://www.python.org/dev/peps/pep-0440/#version-scheme" % target_version)
    return compare_version in match_versions
github eccentricayman / dotfiles / emacs / .emacs.d / .python-environments / default / lib / python2.7 / site-packages / setuptools / dist.py View on Github external
def check_specifier(dist, attr, value):
    """Verify that value is a valid version specifier"""
    try:
        packaging.specifiers.SpecifierSet(value)
    except packaging.specifiers.InvalidSpecifier as error:
        tmpl = (
            "{attr!r} must be a string "
            "containing valid version specifiers; {error}"
        )
        raise DistutilsSetupError(tmpl.format(attr=attr, error=error))