Ejemplo n.º 1
0
def check_solidity_version(url):
    """Check if a repository is a fix repository by checking if it contains atleast one file with version >=0.4.19

    :param url: URL of repository
    :return: True if repository is a fix repo else False
    """
    # clone repo
    path = os.getcwd() + '/data'
    if not os.path.exists(path):
        os.mkdir('data')

    # check if repo has .sol files or not
    response = make_request(url + '/search?q=extension%3Asol', HEADER)
    parsed = BeautifulSoup(response.content, 'html.parser')
    try:
        parsed.find('div', class_='code-list').find('a')['href']
    except Exception as e:
        logging.exception(e)
        logging.info('Does not contains .sol files')
        return False, '0'

    if not clone_repo(url, path):
        return False, '0'

    sol_files = get_sol_files(path + '/' + url.split('/')[-1])

    for sol_file in sol_files:
        try:
            parsed = parser.parse_file(sol_file)
            ver = None
            for child in parsed['children']:
                if child['type'] == 'PragmaDirective':
                    ver = child['value']
                    break
            # ver = parsed['children'][0]['value'].replace('^','')

            if not ver:
                logging.error('File version not found in file ' +
                              str(sol_file))
                continue

            ver = ver.replace('^', '')
            if '<' in ver:
                ver = ver.split('<')[0]
            file_sol_ver = semantic_version.SimpleSpec(ver)

            # checking if version >= 0.4.19
            req_sol_ver = semantic_version.SimpleSpec('>=0.4.19')
            if req_sol_ver.match(file_sol_ver.clause.target):
                shutil.rmtree(path + '/' + url.split('/')[-1])
                return True, len(sol_files)

        except Exception as e:
            logging.exception(e)
            continue

    # delete cloned copy of repo
    shutil.rmtree(path + '/' + url.split('/')[-1])
    return False, '0'
Ejemplo n.º 2
0
def get_filename(datapackage="cord19_cdcs"):
    """get endpoint to download `datapackage`"""
    constraint = __compatible__.get(datapackage)
    assert (
        constraint
        is not None), f"`{datapackage}` is not a supported datapackage name!"
    spec = sv.SimpleSpec(constraint)

    if datapackage == "cord19_cdcs":
        repo = "usnistgov/cord19-cdcs-nist"
        v = spec.select(get_release_versions(repo))
        fname = (
            f"https://github.com/{repo}/releases/download/v{v}/cord19-cdcs-{v}.tar.gz"
        )
        return fname
    elif datapackage in [  # Sci-spaCy
            "en_core_sci_sm",
            "en_core_sci_md",
            "en_core_sci_lg",
            "en_ner_craft_md",
            "en_ner_jnlpba_md",
            "en_ner_bc5cdr_md",
            "en_ner_bionlp13cg_md",
    ]:
        fname = (
            f"https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.2.4/{datapackage}-0.2.4.tar.gz"
        )
        return fname

    else:  # TODO other resources sources?
        raise NotImplementedError
 def _filter_unsupported_templates(self):
     """Remove template descriptors which is not supported."""
     # No need to filter templates if CSE is configured in legacy mode.
     if self.legacy_mode:
         msg = "Skipping filtering templates as CSE is being" \
               " executed in legacy mode"
         self.filtered_cookbook = self.unfiltered_cookbook
         self.logger.debug(msg)
         self.msg_update_callback.general(msg)
         return
     # Fetch current CSE version
     current_cse_version = server_utils.get_installed_cse_version()
     supported_templates = []
     for template_description in self.unfiltered_cookbook['templates']:
         # only include the template if the current CSE version
         # supports it
         # template is supported if current CSE version is between
         # min_cse_version and max_cse_version of the template
         template_supported_cse_versions = semantic_version.SimpleSpec(
             f">={template_description[RemoteTemplateKey.MIN_CSE_VERSION]},"
             f"<={template_description[RemoteTemplateKey.MAX_CSE_VERSION]}")
         msg = f"Template {template_description['name']}"
         if template_supported_cse_versions.match(current_cse_version):
             msg += " is supported"
             supported_templates.append(template_description)
         else:
             msg += " is not supported"
         msg += f" by CSE {current_cse_version}"
         self.logger.debug(msg)
         self.msg_update_callback.general(msg)
     self.filtered_cookbook = {'templates': supported_templates}
     msg = "Successfully filtered unsupported templates."
     self.logger.debug(msg)
     self.msg_update_callback.general(msg)
Ejemplo n.º 4
0
    def get_package(self, name, requirements=None, url=None):
        pkg_id = int(name[3:]) if name.startswith("id=") else 0
        best = None
        for manifest in self.get_installed():
            if url:
                if manifest.get("__src_url") != url:
                    continue
            elif pkg_id and manifest.get("id") != pkg_id:
                continue
            elif not pkg_id and manifest["name"] != name:
                continue
            elif not PkgRepoMixin.is_system_compatible(manifest.get("system")):
                continue

            # strict version or VCS HASH
            if requirements and requirements == manifest["version"]:
                return manifest

            try:
                if requirements and not semantic_version.SimpleSpec(
                        requirements).match(
                            self.parse_semver_version(manifest["version"],
                                                      raise_exception=True)):
                    continue
                if not best or (self.parse_semver_version(manifest["version"],
                                                          raise_exception=True)
                                > self.parse_semver_version(
                                    best["version"], raise_exception=True)):
                    best = manifest
            except ValueError:
                pass

        return best
Ejemplo n.º 5
0
def constraints_fulfilled(constraints, stackhead_config):
    extractFromConstraint = re.compile(r"^([\w.]+)([+><=\s]+(.*))?$")

    for constraint in constraints:
        match = extractFromConstraint.match(constraint)
        (constraint_name, constraint_range) = match.group(1, 2)
        if constraint_name != "stackhead":  # for now only support stackhead
            continue

        if constraint_range is None:
            # todo when extending this for module constraints: check if package exists
            continue

        # remove whitespace
        # @see https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string
        constraint_range = re.sub(r"\s+",
                                  "",
                                  constraint_range,
                                  flags=re.UNICODE)

        constraint_version = ""
        if constraint_name == "stackhead":
            constraint_version = stackhead_config["version"]["current"]

        if semantic_version.Version(
                constraint_version) not in semantic_version.SimpleSpec(
                    constraint_range):
            return False
    return True
Ejemplo n.º 6
0
def check_package(strategy, pkg, level=Level.STANDARD):
    whitelisted = (pkg['name'] in strategy.AUTHORIZED_PACKAGES
                   and (semantic_version.SimpleSpec(
                       strategy.AUTHORIZED_PACKAGES[pkg['name']]).match(
                           semantic_version.Version.coerce(pkg['version'])) or
                        (level == Level.STANDARD
                         and strategy.AUTHORIZED_PACKAGES[pkg['name']] == '')))
    if whitelisted:
        return Reason.OK

    at_least_one_unauthorized = False
    count_authorized = 0
    for license in pkg['licenses']:
        lower = license.lower()
        if lower in strategy.UNAUTHORIZED_LICENSES:
            at_least_one_unauthorized = True
        if lower in strategy.AUTHORIZED_LICENSES:
            count_authorized += 1

    if (count_authorized and level is Level.STANDARD) \
            or (count_authorized and not at_least_one_unauthorized
                and level is Level.CAUTIOUS) \
            or (count_authorized and count_authorized == len(pkg['licenses'])
                and level is Level.PARANOID):
        return Reason.OK

    # if not OK and at least one unauthorized
    if at_least_one_unauthorized:
        return Reason.UNAUTHORIZED

    return Reason.UNKNOWN
Ejemplo n.º 7
0
 def requirements(self, value):
     if not value:
         self._requirements = None
         return
     self._requirements = (value
                           if isinstance(value, semantic_version.SimpleSpec)
                           else semantic_version.SimpleSpec(str(value)))
Ejemplo n.º 8
0
    def max_satisfying_repo_version(self, versions, requirements=None):
        def _cmp_dates(datestr1, datestr2):
            date1 = util.parse_date(datestr1)
            date2 = util.parse_date(datestr2)
            if date1 == date2:
                return 0
            return -1 if date1 < date2 else 1

        semver_spec = None
        try:
            semver_spec = (semantic_version.SimpleSpec(requirements)
                           if requirements else None)
        except ValueError:
            pass

        item = {}

        for v in versions:
            semver_new = self.parse_semver_version(v["name"])
            if semver_spec:
                if not semver_new or semver_new not in semver_spec:
                    continue
                if not item or self.parse_semver_version(
                        item["name"]) < semver_new:
                    item = v
            elif requirements:
                if requirements == v["name"]:
                    return v

            else:
                if not item or _cmp_dates(item["released"],
                                          v["released"]) == -1:
                    item = v
        return item
Ejemplo n.º 9
0
    async def get_latest_matching_version(self,
                                          collection: str,
                                          version_spec: str,
                                          pre: bool = False) -> semver.Version:
        """
        Get the latest version of a collection that matches a specification.

        :arg collection: Namespace.collection identifying a collection.
        :arg version_spec: String specifying the allowable versions.
        :kwarg pre: If True, allow prereleases (versions which have the form X.Y.Z.SOMETHING).
            This is **not** for excluding 0.Y.Z versions.  The default is False.
        :returns: :obj:`semantic_version.Version` of the latest collection version that satisfied
            the specification.

        .. seealso:: For the format of the version_spec, see the documentation
            of :obj:`semantic_version.SimpleSpec`
        """
        versions = await self.get_versions(collection)
        versions = [semver.Version(v) for v in versions]
        versions.sort(reverse=True)

        spec = semver.SimpleSpec(version_spec)
        for version in (v for v in versions if v in spec):
            # If we're excluding prereleases and this is a prerelease, then skip it.
            if not pre and version.prerelease:
                continue
            return version

        # No matching versions were found
        raise NoSuchVersion(
            f'{version_spec} did not match with any version of {collection}.')
async def main(
    args: argparse.Namespace,
    log: logging.Logger,
) -> int:

    version_specs = [semver.SimpleSpec(spec) for spec in args.version_spec]
    output_dir_path = args.output_dir_path.absolute()
    output_dir_path.mkdir(parents=True, exist_ok=True)

    log.debug(
        "args: version_specs=%s, download_zip=%s, download_exe=%s, output_dir_path=%s",
        list(map(str, version_specs)),
        args.download_zip,
        args.download_exe,
        output_dir_path,
    )

    if not args.download_zip and not args.download_exe:
        log.error(
            "both EXE and ZIP are disabled: at least one of them must be enabled"
        )
        return -1

    async with aiohttp.ClientSession() as session:
        await run(
            http_session=session,
            version_specs=version_specs,
            download_zip=args.download_zip,
            download_exe=args.download_exe,
            output_dir_path=output_dir_path,
            log=log,
        )

    return 0
Ejemplo n.º 11
0
    def _check_dependencies_format(self, attribute, dependencies):
        """Check type and format of dependencies collection and version."""
        for collection, version_spec in dependencies.items():
            if not isinstance(collection, str):
                self.value_error("Expecting depencency to be string")
            if not isinstance(version_spec, str):
                self.value_error("Expecting depencency version to be string")

            try:
                namespace, name = collection.split('.')
            except ValueError:
                self.value_error(f"Invalid dependency format: '{collection}'")

            for value in [namespace, name]:
                if not re.match(constants.NAME_REGEXP, value):
                    self.value_error(
                        f"Invalid dependency format: '{value}' "
                        f"in '{namespace}.{name}'")

            if namespace == self.namespace and name == self.name:
                self.value_error("Cannot have self dependency")

            try:
                semantic_version.SimpleSpec(version_spec)
            except ValueError:
                self.value_error(
                    "Dependency version spec range invalid: "
                    f"{collection} {version_spec}")
Ejemplo n.º 12
0
    def _is_compatible(self, has, needs):
        """Is a provider and consumer specification compatible.

        Args:
            has: a tuple (pair) of strings. The first string is a
                string naming the service provided. The second is a
                string giving the version of the provided service.
            needs: a tuple (pair) of strings. The first string is a
                string naming an acceptable services type. The second is a
                string specifying acceptable versions for the service
                type. The version specification can be in any format that is
                compatible with the
                `semver <https://pypi.org/project/semver/>`_ Python package.

        Returns:
            bool: True if the provider and consumer specification are
               compatible.
        """
        # if consumer has no constraints
        # compatibility is true by default
        if not needs:
            return True

        # if consumer has constraints but provider
        # has no specification compatibility can not
        # be determined and is hence false by default
        if not has and needs:
            return False

        # By now we know both consumer and provider have a
        # constraint specification so we check if the
        # constraint type is the same
        has_type = self._normalized_type(has)
        needs_type = self._normalized_type(needs)
        if has_type != needs_type:
            return False

        # By now we know consumer and provider have the
        # same constraint type so we check if the constraints
        # are further qualified by version specifications

        # If consumer is not qualified, provider and
        # consumer are compatible by default
        if not self._has_version(needs):
            return True

        # If consumer is qualified but provider is not there
        # is no way to determine compatibility so it is False
        # by default
        if not self._has_version(has):
            return False

        # Both consumer and provider are qualified so we
        # check compatibility of version
        spec = semver.SimpleSpec(self._normalized_version(needs))
        got = semver.Version.coerce(self._normalized_version(has))

        return spec.match(got)
Ejemplo n.º 13
0
    async def _get_latest_matching_version(self, collection, version_spec):
        versions = await self.galaxy_client.get_versions(collection)
        versions = [semver.Version(v) for v in versions]
        versions.sort(reverse=True)

        spec = semver.SimpleSpec(version_spec)
        for version in (v for v in versions if v in spec):
            return version

        # No matching versions were found
        return None
Ejemplo n.º 14
0
def version(requirement: str,
            current: str = __version__,
            package_name="gdsfactory") -> None:
    """Raises error if current version does not match requirement."""

    s = semantic_version.SimpleSpec(requirement)
    if not s.match(semantic_version.Version(current)):
        raise ValueError(
            f"{package_name} requirement {requirement}\n"
            f"not compatible your current installed version {current}\n"
            "you can run:\n"
            f"pip install {package_name} {requirement}\n")
Ejemplo n.º 15
0
def MatchVersionSpecification(versionSpec: list,
                              version: semantic_version.Version):
    versionSpecStr = ''
    for versionTuple in versionSpec:
        if len(versionSpecStr) > 0:
            versionSpecStr += ','
        versionSpecStr += versionTuple[0] + versionTuple[1]

    if len(versionSpecStr) > 0:
        s = semantic_version.SimpleSpec(versionSpecStr)
        return s.match(version)
    else:
        return True
Ejemplo n.º 16
0
def main(node_modules, include_unspecified):
    '''
    Node ES6 matrix: https://node.green/#ES2016
    '''
    n_packages = 0
    n_engines = 0
    n_no_engines = 0

    to_transpile = []

    for package_config in glob.glob(
            os.path.join(node_modules, '*', 'package.json')):
        n_packages += 1

        with open(package_config, 'r') as f:
            package = json.load(f)

        try:
            engines = package['engines']

        except KeyError:
            n_no_engines += 1

            if include_unspecified:
                to_transpile.append(package_config)

        except:
            continue

        else:
            print('{0}: {1}'.format(package_config, engines))

            max_node_version = semantic_version.Version('0.12.18')

            package_node_version = get_formatted_node_version(engines)

            if max_node_version in semantic_version.SimpleSpec(
                    package_node_version):
                print('{} includes max version'.format(package_config))

            else:
                print('{} exceeds max version'.format(package_config))
                to_transpile.append(package_config)

            n_engines += 1

    print('Found {0} packages, {1} with engines, {2} without engines'.format(
        n_packages, n_engines, n_no_engines))
    print('Recommend transpiling {} packages'.format(len(to_transpile)))
    pprint.pprint([os.path.dirname(package) for package in to_transpile])
Ejemplo n.º 17
0
def test_convert_caret_specification():
    spec = ">=1.1.2"
    assert et_micc.utils.convert_caret_specification(spec) == spec
    spec = "^1.1.2"
    spec_new = et_micc.utils.convert_caret_specification(spec)
    assert spec_new == ">=1.1.2,<2.0.0"
    assert     sv.SimpleSpec("1.1.2").match(sv.Version("1.1.2"))
    assert not sv.Version("1.1.1") in sv.SimpleSpec(spec_new)
    assert     sv.Version("1.1.2") in sv.SimpleSpec(spec_new)
    assert     sv.Version("1.1.2") in sv.SimpleSpec(spec_new)
    assert     sv.Version("1.2.2") in sv.SimpleSpec(spec_new)
    assert not sv.Version("2.0.0") in sv.SimpleSpec(spec_new)
    assert not sv.Version("2.2.2") in sv.SimpleSpec(spec_new)
    def _filter_unsupported_templates(self):
        """Remove template descriptors which is not supported."""
        # No need to filter templates if CSE is configured in legacy mode.
        if self.legacy_mode:
            msg = "Skipping filtering templates as CSE is being" \
                  " executed in legacy mode"
            self.filtered_cookbook = self.unfiltered_cookbook
            self.logger.debug(msg)
            self.msg_update_callback.general(msg)
            return
        # Cookbook version 1.0 doesn't have supported version information.
        if self.cookbook_version < \
                RemoteTemplateCookbookVersion.Version2.value:
            msg = "Skipping filtering templates as cookbook version " \
                f"{self.cookbook_version} doesn't have supported " \
                "CSE version information."
            self.logger.debug(msg)
            self.msg_update_callback.general(msg)
            return
        # Fetch current CSE version
        current_cse_version = server_utils.get_installed_cse_version()
        supported_templates = []
        remote_template_key = server_utils.get_template_descriptor_keys(
            self.cookbook_version)  # noqa: E501
        for template_description in self.unfiltered_cookbook['templates']:
            # only include the template if the current CSE version
            # supports it
            # template is supported if current CSE version is between
            # min_cse_version and max_cse_version of the template
            template_supported_cse_versions = semantic_version.SimpleSpec(
                f">={template_description[remote_template_key.MIN_CSE_VERSION]},"  # noqa: E501
                f"<={template_description[remote_template_key.MAX_CSE_VERSION]}"
            )  # noqa: E501
            msg = f"Template {template_description['name']}"
            if template_supported_cse_versions.match(current_cse_version):
                msg += " is supported"
                supported_templates.append(template_description)
            else:
                msg += " is not supported"
            msg += f" by CSE {current_cse_version}"
            self.logger.debug(msg)
            self.msg_update_callback.general(msg)
        self.filtered_cookbook = self.unfiltered_cookbook
        # update templates list with only supported templates
        self.filtered_cookbook['templates'] = supported_templates

        msg = "Successfully filtered unsupported templates."
        self.logger.debug(msg)
        self.msg_update_callback.general(msg)
Ejemplo n.º 19
0
 def verify_required_version(self):
     """Verify that the required version for the pod is met."""
     if self.pod.grow_version is None:
         return
     sem_current = semantic_version.Version(self.current_version)
     grow_version_pattern = '{}'.format(self.pod.grow_version)
     # Include pre-releases in the version check.
     if '-' not in grow_version_pattern:
         grow_version_pattern = '{}-'.format(grow_version_pattern)
     spec_required = semantic_version.SimpleSpec(grow_version_pattern)
     if sem_current not in spec_required:
         text = 'ERROR! Pod requires Grow SDK version: {}'.format(
             self.pod.grow_version)
         logging.error(colors.stylize(text, colors.ERROR))
         raise LatestVersionCheckError(text)
Ejemplo n.º 20
0
def check_package(pkg_name, spec='*', is_optional=False):
    try:
        spec_pattern = semantic_version.SimpleSpec(spec)
        pkg_version = pkg_resources.get_distribution(pkg_name).version
        version = semantic_version.Version(pkg_version)
        if not spec_pattern.match(version):
            raise Exception('Package "{0}" version ({1}) does not match "{2}" '.format(pkg_name, version, spec) +
                            'Please run: pip install -U {0}'.format(pkg_name))
    except pkg_resources.DistributionNotFound:
        if is_optional:
            raise Exception('Optional package "{0}" is not installed. '.format(pkg_name) +
                            'Please run: pip install {0}'.format(pkg_name))
        else:
            raise Exception('Package "{0}" is not installed. '.format(pkg_name) +
                            'Please run: pip install {0}'.format(pkg_name))
Ejemplo n.º 21
0
    async def get_latest_matching_version(self,
                                          collection: str,
                                          version_spec: str,
                                          pre: bool = False) -> semver.Version:
        """
        Get the latest version of a collection that matches a specification.

        :arg collection: Namespace.collection identifying a collection.
        :arg version_spec: String specifying the allowable versions.
        :kwarg pre: If True, allow prereleases (versions which have the form X.Y.Z.SOMETHING).
            This is **not** for excluding 0.Y.Z versions.  non-pre-releases are still
            preferred over pre-releases (for instance, with version_spec='>2.0.0-a1,<3.0.0'
            and pre=True, if the available versions are 2.0.0-a1 and 2.0.0-a2, then 2.0.0-a2
            will be returned.  If the available versions are 2.0.0 and 2.1.0-b2, 2.0.0 will be
            returned since non-pre-releases are preferred.  The default is False
        :returns: :obj:`semantic_version.Version` of the latest collection version that satisfied
            the specification.

        .. seealso:: For the format of the version_spec, see the documentation
            of :obj:`semantic_version.SimpleSpec`

        .. versionchanged:: 0.37.0
            Giving True to the ``pre`` parameter now means that prereleases will be
            *allowed* but stable releases will still be *preferred*.  Previously, the
            latest release, whether stable or prerelease was returned when pre was True.
        """
        versions = await self.get_versions(collection)
        versions = [semver.Version(v) for v in versions]
        versions.sort(reverse=True)

        spec = semver.SimpleSpec(version_spec)
        prereleases = []
        for version in (v for v in versions if v in spec):
            # If this is a pre-release, first check if there's a non-pre-release that
            # will satisfy the version_spec.
            if version.prerelease:
                prereleases.append(version)
                continue
            return version

        # We did not find a stable version that satisies the version_spec.  If we
        # allow prereleases, return the latest of those here.
        if pre and prereleases:
            return prereleases[0]

        # No matching versions were found
        raise NoSuchVersion(
            f'{version_spec} did not match with any version of {collection}.')
Ejemplo n.º 22
0
    def version(self, version: Optional[str]) -> Optional[ChartVersionInfo]:
        """
        Returns a chart version info.

        :param version: version to locate. If None, returns the latest version. Can be a semver SimpleSpec.
        :return: the chart version information, or None if not found
        """
        if version is None or version == "":
            return self.latest

        versionspec = semantic_version.SimpleSpec(version)

        for r in self.versions:
            if versionspec.match(r.version_info):
                return r
        return None
Ejemplo n.º 23
0
    def பதிப்பு_கண்டறி(தன், நிரல்மொழி, பதிப்பு):
        பதிப்புகள் = தன்.பதிப்புகள்(நிரல்மொழி)
        if not பதிப்புகள்:
            return
        பதிப்புகள் = [semantic_version.Version(ப) for ப in பதிப்புகள்]

        if not பதிப்புகள்:
            return None
        if பதிப்பு is None:
            return str(பதிப்புகள்[-1])

        _பதிப்பு = semantic_version.Version.coerce(str(பதிப்பு))

        try:
            return next(str(ப) for ப in பதிப்புகள்[::-1] if semantic_version.SimpleSpec(f'<={_பதிப்பு}').match(ப))
        except StopIteration:
            return str(பதிப்புகள்[-1])
Ejemplo n.º 24
0
    def check_appcast(self) -> Optional[EDMCVersion]:
        """
        Manually (no Sparkle or WinSparkle) check the update_feed appcast file
        to see if any listed version is semantically greater than the current
        running version.
        :return: EDMCVersion or None if no newer version found
        """
        import requests
        from xml.etree import ElementTree

        newversion = None
        items = {}
        try:
            r = requests.get(update_feed, timeout=10)
        except requests.RequestException as ex:
            print('Error retrieving update_feed file: {}'.format(str(ex)),
                  file=sys.stderr)

            return None

        try:
            feed = ElementTree.fromstring(r.text)
        except SyntaxError as ex:
            print('Syntax error in update_feed file: {}'.format(str(ex)),
                  file=sys.stderr)

            return None

        for item in feed.findall('channel/item'):
            ver = item.find('enclosure').attrib.get(
                '{http://www.andymatuschak.org/xml-namespaces/sparkle}version')
            # This will change A.B.C.D to A.B.C+D
            sv = semantic_version.Version.coerce(ver)

            items[sv] = EDMCVersion(
                version=ver,  # sv might have mangled version
                title=item.find('title').text,
                sv=sv)

        # Look for any remaining version greater than appversion
        simple_spec = semantic_version.SimpleSpec('>' + appversion)
        newversion = simple_spec.select(items.keys())

        if newversion:
            return items[newversion]
        return None
Ejemplo n.º 25
0
def test_spec_requirements():
    assert PackageSpec("[email protected]") == PackageSpec(name="foo",
                                                   requirements="1.2.3")
    assert PackageSpec(
        name="foo",
        requirements=semantic_version.Version("1.2.3")) == PackageSpec(
            name="foo", requirements="1.2.3")
    assert PackageSpec("bar @ ^1.2.3") == PackageSpec(name="bar",
                                                      requirements="^1.2.3")
    assert PackageSpec("13 @ ~2.0") == PackageSpec(id=13, requirements="~2.0")
    assert PackageSpec(
        name="hello",
        requirements=semantic_version.SimpleSpec("~1.2.3")) == PackageSpec(
            name="hello", requirements="~1.2.3")
    spec = PackageSpec("id=20 @ !=1.2.3,<2.0")
    assert not spec.external
    assert isinstance(spec.requirements, semantic_version.SimpleSpec)
    assert semantic_version.Version("1.3.0-beta.1") in spec.requirements
    assert spec == PackageSpec(id=20, requirements="!=1.2.3,<2.0")
Ejemplo n.º 26
0
def main(args):
    input_file = open(args.file, 'r')
    try:
        constraint = hcl.load(input_file)['terraform']['required_version']
    except:
        # Using the latest version
        constraint = '>= 0.1.0'
    token = get_token(args.username, args.password)
    all_versions = sorted(get_versions(args.repository, token),
                          key=LooseVersion)
    # Get the required versions range
    valid_versions = semantic_version.SimpleSpec(format_constraint(constraint))
    while all_versions:
        match = all_versions.pop()
        if semantic_version.validate(match) \
                and not(semantic_version.Version(match).prerelease) \
                and semantic_version.Version(match) in valid_versions:
            # Valid x.y.z & release & in the required versions range
            break
        match = 'No match'
    print(match)