Python semantic_version.Spec() Examples

The following are 26 code examples of semantic_version.Spec(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module semantic_version , or try the search function .
Example #1
Source File: dependency.py    From poet with MIT License 6 votes vote down vote up
def __init__(self, name, constraint, category='main'):
        self._name = name
        self._constraint = constraint
        self._optional = False
        self._accepts_prereleases = False
        self._category = category
        self._python = [Spec('*')]

        if isinstance(constraint, dict):
            if 'python' in constraint:
                python = constraint['python']

                if not isinstance(python, list):
                    python = [python]

                self._python = [Spec(p) for p in python]

            if 'optional' in constraint:
                self._optional = constraint['optional']

            if 'version' in constraint:
                self._constraint = constraint['version']

        self._normalized_constraint = self._normalize(constraint) 
Example #2
Source File: test_geth_installation.py    From py-geth with MIT License 6 votes vote down vote up
def test_geth_installation_as_function_call(monkeypatch, tmpdir, platform, version):
    if get_platform() != platform:
        pytest.skip("Wrong platform for install script")

    base_install_path = str(tmpdir.mkdir("temporary-dir"))
    monkeypatch.setenv('GETH_BASE_INSTALL_PATH', base_install_path)

    # sanity check that it's not already installed.
    executable_path = get_executable_path(version)
    assert not os.path.exists(executable_path)

    install_geth(identifier=version, platform=platform)

    assert os.path.exists(executable_path)
    monkeypatch.setenv('GETH_BINARY', executable_path)

    actual_version = get_geth_version()
    expected_version = semantic_version.Spec(version.lstrip('v'))

    assert actual_version in expected_version 
Example #3
Source File: __init__.py    From quay with Apache License 2.0 6 votes vote down vote up
def v2_support_enabled():
    docker_ver = docker_version(request.user_agent.string)

    # Check if our version is one of the blacklisted versions, if we can't
    # identify the version (None) we will fail open and assume that it is
    # newer and therefore should not be blacklisted.
    if docker_ver is not None and Spec(app.config["BLACKLIST_V2_SPEC"]).match(docker_ver):
        abort(404)

    response = make_response("true", 200)

    if get_authenticated_context() is None:
        response = make_response("true", 401)

    response.headers.extend(get_auth_headers())
    return response 
Example #4
Source File: models.py    From appstore with GNU Affero General Public License v3.0 6 votes vote down vote up
def is_compatible(self, platform_version, inclusive=False):
        """Checks if a release is compatible with a platform version

        :param platform_version: the platform version, not required to be
                                 semver compatible
        :param inclusive: if True the check will also return True if an app
                          requires 9.0.1 and the given platform version is 9.0
        :return: True if compatible, otherwise false
        """

        min_version = Version(pad_min_version(platform_version))
        spec = Spec(self.platform_version_spec)
        if inclusive:
            max_version = Version(pad_max_inc_version(platform_version))
            return (min_version in spec or max_version in spec)
        else:
            return min_version in spec 
Example #5
Source File: conftest.py    From py-solc with MIT License 6 votes vote down vote up
def FOO_SOURCE(supported_solc_version, solc_version):
    if solc_version in Spec('<0.4.17'):
        return textwrap.dedent('''\
            pragma solidity ^0.4.0;

            contract Foo {
                function Foo() {}

                function return13() public returns (uint) {
                    return 13;
                }
            }
            ''')
    else:
        return textwrap.dedent('''\
            pragma solidity ^0.4.17;

            contract Foo {
                function Foo() public {}

                function return13() public pure returns (uint) {
                    return 13;
                }
            }
            ''') 
Example #6
Source File: dependency.py    From poet with MIT License 5 votes vote down vote up
def _spec(self, version):
        try:
            return Spec(version)
        except ValueError:
            return Spec(str(Version.coerce(version))) 
Example #7
Source File: conftest.py    From py-solc with MIT License 5 votes vote down vote up
def is_new_key_format():
    return get_solc_version() in Spec('>=0.4.9') 
Example #8
Source File: version.py    From yotta with Apache License 2.0 5 votes vote down vote up
def __init__(self, version_spec):
        if not version_spec:
            version_spec = '*'
        # add support for version specs that are unadorned versions, or a
        # single equals
        if re.match('^[0-9]', version_spec):
            version_spec = '==' + version_spec
        elif re.match('^=[0-9]', version_spec):
            version_spec = '=' + version_spec
        # add support for the ~ and ^ version specifiers:
        #  ~1.2.3 := >=1.2.3-0 <1.3.0-0
        #  ^1.2.3 := >=1.2.3-0 <2.0.0-0
        #  ^0.1.2 := 0.1.2 exactly (for 0.x.x versions)
        elif re.match('^\^', version_spec):
            v = semantic_version.Version(version_spec[1:])
            if v.major == 0:
                # for 0. releases, ^ means exact version only
                version_spec = '==' + str(v)
            else:
                v2 = Version(version_spec[1:])
                v2.bump('major')
                version_spec = '>=' + str(v) + ',<' +str(v2)
        elif re.match('^~', version_spec):
            v = semantic_version.Version(version_spec[1:])
            v2 = Version(version_spec[1:])
            v2.bump('minor')
            version_spec = '>=' + str(v) + ',<' +str(v2)
        super(Spec, self).__init__(version_spec)

    # base type contains function checks the type, so must replace it 
Example #9
Source File: version.py    From yotta with Apache License 2.0 5 votes vote down vote up
def __cmp__(self, other):
        # if the other is an unwrapped version (used within the Spec class)
        if isinstance(other, semantic_version.Version):
            other_is_specific_ver = True
            other_is_unwrapped = True
        elif not hasattr(other, 'version'):
            return NotImplemented
        else:
            other_is_specific_ver = isinstance(other.version, semantic_version.Version)
            other_is_unwrapped = False

        self_is_specific_ver  = isinstance(self.version, semantic_version.Version)

        if isinstance(self.version, TipVersion) and other_is_specific_ver:
            return 1
        elif (not other_is_unwrapped) and isinstance(other.version, TipVersion) and self_is_specific_ver:
            return -1
        elif self_is_specific_ver and other_is_specific_ver:
            if other_is_unwrapped:
                return semantic_version.Version.__cmp__(self.version, other)
            else:
                return semantic_version.Version.__cmp__(self.version, other.version)
        elif isinstance(self.version, TipVersion) and isinstance(other.version, TipVersion):
            raise Exception('Comparing two "tip" versions is undefined')
        else:
            raise Exception('Unsupported version comparison: "%s" vs. "%s"' % (self.version, other.version)) 
Example #10
Source File: util.py    From async-hvac with Apache License 2.0 5 votes vote down vote up
def match_version(spec):
    output = subprocess.check_output(['vault', 'version']).decode('ascii')
    version = Version(VERSION_REGEX.match(output).group(1))

    return Spec(spec).match(version) 
Example #11
Source File: versioning.py    From appstore with GNU Affero General Public License v3.0 5 votes vote down vote up
def version_in_spec(version: str, spec: str) -> bool:
    """
    Checks if a string version is in a spec
    :param version:
    :param spec:
    :return:
    """
    return Version(version) in Spec(spec) 
Example #12
Source File: test_solc_installation.py    From py-solc with MIT License 5 votes vote down vote up
def test_solc_installation_as_function_call(monkeypatch, tmpdir, platform, version):
    if get_platform() != platform:
        pytest.skip("Wront platform for install script")

    base_install_path = str(tmpdir.mkdir("temporary-dir"))
    monkeypatch.setenv('SOLC_BASE_INSTALL_PATH', base_install_path)

    # sanity check that it's not already installed.
    executable_path = get_executable_path(version)
    assert not os.path.exists(executable_path)

    install_solc(identifier=version, platform=platform)

    assert os.path.exists(executable_path)
    monkeypatch.setenv('SOLC_BINARY', executable_path)

    extract_path = get_extract_path(version)
    if os.path.exists(extract_path):
        contains_so_file = any(
            os.path.basename(path).partition(os.path.extsep)[2] == 'so'
            for path
            in os.listdir(extract_path)
        )
        if contains_so_file:
            monkeypatch.setenv('LD_LIBRARY_PATH', extract_path)

    actual_version = get_solc_version()
    expected_version = semantic_version.Spec(version.lstrip('v'))

    assert actual_version in expected_version 
Example #13
Source File: model_factory.py    From margipose with Apache License 2.0 5 votes vote down vote up
def __init__(self, model_type, version_spec):
        super().__init__()
        self.model_type = model_type
        self.version_spec = Spec(version_spec) 
Example #14
Source File: test_solc_supports_standard_json.py    From py-solc with MIT License 5 votes vote down vote up
def test_solc_supports_standard_json_interface():
    version = get_solc_version()

    if version in semantic_version.Spec("<0.4.11"):
        assert not solc_supports_standard_json_interface()
    else:
        assert solc_supports_standard_json_interface() 
Example #15
Source File: dependency.py    From poet with MIT License 5 votes vote down vote up
def is_python_restricted(self):
        return self._python != [Spec('*')] 
Example #16
Source File: conftest.py    From py-solc with MIT License 5 votes vote down vote up
def supported_solc_version(solc_version):
    if solc_version not in Spec('>=0.4.1,<=0.4.25,!=0.4.10,!=0.4.3,!=0.4.4,!=0.4.5'):
        raise AssertionError("Unsupported compiler version: {0}".format(solc_version))

    return solc_version 
Example #17
Source File: builder.py    From poet with MIT License 5 votes vote down vote up
def _classifiers(self, poet):
        """
        Builds the classifiers list from the
        specified Python versions.
        
        :param poet: The Poet instance for which to build.
        :type poet: poet.poet.Poet
        
        :rtype: list
        """
        classifers = ['Programming Language :: Python']
        compatible_versions = {}

        for python in poet.python_versions:
            constraint = Spec(python)

            for major in [2, 3]:
                available_versions = self.PYTHON_VERSIONS[major]

                for version in available_versions:
                    if Version.coerce(version) in constraint:
                        if major not in compatible_versions:
                            compatible_versions[major] = []

                        compatible_versions[major].append(version)

        for major in sorted(list(compatible_versions.keys())):
            versions = compatible_versions[major]
            classifer_template = 'Programming Language :: Python :: {}'

            classifers.append(classifer_template.format(major))

            for version in versions:
                classifers.append(classifer_template.format(version))

        return classifers 
Example #18
Source File: version_parser.py    From poet with MIT License 5 votes vote down vote up
def parse_constraints(self, constraints):
        if not isinstance(constraints, list):
            constraints = constraints.replace(', ', ',')
        else:
            constraints = ','.join(constraints)

        if constraints not in self.__class__._constraints:
            specs = Spec(constraints)

            self.__class__._constraints[constraints] = specs

        return self.__class__._constraints[constraints] 
Example #19
Source File: version_check.py    From federated with Apache License 2.0 5 votes vote down vote up
def is_tensorflow_version_newer(version: str, tf_module):
  """Determines the Tensorflow module is newer than a specified version.

  This function should be used when we wish to take dependency on some behavior
  present in newer but not older versions of TensorFlow. When adding a usage
  of this, please perform the following steps:

  1. File a bug to clean up the usage of this check--once the latest released
     TensorFlow version contains this behavior, we want to remove it.

  2. Log in the true and false cases, and ensure that the default behavior is
     the one you expect.

  Args:
    version: a `str` in the semantic versioning format 'major.minor.patch'.
    tf_module: the TensorFlow module to assert the version against.

  Returns:
    `True` iff `tf_module` is versions at or newer than `version` string, or
  the is determined to be a nightly pre-release version of TensorFlow.
  """
  tf_version = semantic_version.Version(tf_module.version.VERSION)
  if tf_version.prerelease:
    # tf-nightly uses versions like MAJOR.MINOR.PATCH-devYYYYMMDD
    if tf_version.prerelease[0].startswith('dev2020'):
      return True
  version_spec = semantic_version.Spec('>={v}'.format(v=version))
  return version_spec.match(tf_version) 
Example #20
Source File: extension.py    From setuptools-rust with MIT License 5 votes vote down vote up
def get_rust_version(self):
        if self.rust_version is None:
            return None
        try:
            return semantic_version.Spec(self.rust_version)
        except ValueError:
            raise DistutilsSetupError(
                "Can not parse rust compiler version: %s", self.rust_version
            ) 
Example #21
Source File: test_functional_dockerutils.py    From agentless-system-crawler with Apache License 2.0 5 votes vote down vote up
def test_fix_version(self):
        import semantic_version
        ver = u'17.03.01-ce'
        fixed_ver = _fix_version(ver)
        assert fixed_ver == u'17.3.1'
        VERSION_SPEC = semantic_version.Spec('>=1.10.0')
        assert VERSION_SPEC.match(semantic_version.Version(fixed_ver)) is True 
Example #22
Source File: semver.py    From appr with Apache License 2.0 5 votes vote down vote up
def select_version(versions_str, query, stable=False):
    if isinstance(query, str):
        query = query.split(",")
    query = [x.replace(" ", "") for x in query]
    stable = True
    if "-" in str(query):
        stable = False
    spec = Spec(*query)
    return spec.select(versions(versions_str, stable)) 
Example #23
Source File: scons.py    From apio with GNU General Public License v2.0 5 votes vote down vote up
def check_pip_packages(self, board_data):
        prog_info = board_data.get('programmer')
        content = self.resources.programmers.get(prog_info.get('type'))
        all_pip_packages = self.resources.distribution.get('pip_packages')

        pip_packages = content.get('pip_packages') or []
        for pip_pkg in pip_packages:
            try:
                # Check pip_package version
                spec = semantic_version.Spec(all_pip_packages.get(pip_pkg, ''))
                pkg_version = pkg_resources.get_distribution(pip_pkg).version
                version = semantic_version.Version(pkg_version)
                if not spec.match(version):
                    click.secho(
                        'Error: \'{}\' '.format(pip_pkg) +
                        'version ({}) '.format(version) +
                        'does not match {}'.format(spec),
                        fg='red')
                    click.secho('Please run:\n'
                                '   pip install -U apio[{}]'.format(pip_pkg),
                                fg='yellow')
                    raise Exception
            except pkg_resources.DistributionNotFound:
                click.secho(
                    'Error: \'{}\' is not installed'.format(pip_pkg),
                    fg='red')
                click.secho('Please run:\n'
                            '   pip install -U apio[{}]'.format(pip_pkg),
                            fg='yellow')
                raise Exception
            try:
                # Check pip_package itself
                __import__(pip_pkg)
            except Exception as e:
                # Exit if a package is not working
                python_version = util.get_python_version()
                message = '\'{}\' not compatible with '.format(pip_pkg)
                message += 'Python {}'.format(python_version)
                message += '\n       {}'.format(e)
                raise Exception(message) 
Example #24
Source File: util.py    From apio with GNU General Public License v2.0 5 votes vote down vote up
def check_package_version(version, spec_version):
    try:
        spec = semantic_version.Spec(spec_version)
        return semantic_version.Version(version) in spec
    except ValueError:
        pass 
Example #25
Source File: store.py    From ftcommunity-TXT with GNU General Public License v3.0 4 votes vote down vote up
def append_parameter(package, app, id, lkey, parms):
    val = None

    # is there a language key to try?
    if lkey:
        # no app name given: we are parsing a manifest and the languages
        # have seperate sections
        if not app:
            if package.has_option(lkey, id):
                val = package.get(lkey, id);

        # app name was given. we are parsing the 00packages and language 
        # specific entries have the form key_kley: ...
        else:
            if package.has_option(app, id+'_'+lkey):
                val = package.get(app, id+'_'+lkey);

    # nothing language specifg found, try "normal"
    if not app: app = 'app'
    if not val and package.has_option(app, id):
        val = package.get(app, id);

    # category entries need special treatment
    if val and id == 'category':
        val = get_category_name(val.lower())

    # version entries are parsed into semantic versions
    # missing or invalid version entries are interpreted
    # as '0.0.0-missing' or '0.0.0-invalid+...', 
    # i.e. a "version" that is guaranteed to be lower than
    # any real version
    if id == 'version':
        if val:
            try:
                val = semantic_version.Version.coerce(val)
            except ValueError:
                val = semantic_version.Version("0.0.0-invalid+" + val)
        else:
            val = semantic_version.Version("0.0.0-missing")

    # ... and 'firmware' entries into semantic version specs
    if val and id == 'firmware':
        try:
            val = semantic_version.Spec(val)
        except ValueError:
            val = None

    if val:
        parms[id] = val

# a rotating "i am busy" widget to be shown during network io 
Example #26
Source File: store.py    From ftcommunity-TXT with GNU General Public License v3.0 4 votes vote down vote up
def append_parameter(package, app, id, lkey, parms):
    val = None

    # is there a language key to try?
    if lkey:
        # no app name given: we are parsing a manifest and the languages
        # have seperate sections
        if not app:
            if package.has_option(lkey, id):
                val = package.get(lkey, id);

        # app name was given. we are parsing the 00packages and language 
        # specific entries have the form key_kley: ...
        else:
            if package.has_option(app, id+'_'+lkey):
                val = package.get(app, id+'_'+lkey);

    # nothing language specifg found, try "normal"
    if not app: app = 'app'
    if not val and package.has_option(app, id):
        val = package.get(app, id);

    # category entries need special treatment
    if val and id == 'category':
        val = get_category_name(val.lower())

    # version entries are parsed into semantic versions
    # missing or invalid version entries are interpreted
    # as '0.0.0-missing' or '0.0.0-invalid+...', 
    # i.e. a "version" that is guaranteed to be lower than
    # any real version
    if id == 'version':
        if val:
            try:
                val = semantic_version.Version.coerce(val)
            except ValueError:
                val = semantic_version.Version("0.0.0-invalid+" + val)
        else:
            val = semantic_version.Version("0.0.0-missing")

    # ... and 'firmware' entries into semantic version specs
    if val and id == 'firmware':
        try:
            val = semantic_version.Spec(val)
        except ValueError:
            val = None

    if val:
        parms[id] = val

# a rotating "i am busy" widget to be shown during network io