Exemplo n.º 1
0
def add_release(
        config: ChangelogConfig,  # pylint: disable=too-many-arguments
        changes: ChangesBase,
        plugins: List[PluginDescription],
        fragments: List[ChangelogFragment],
        version: str,
        codename: Optional[str],
        date: datetime.date) -> None:
    """
    Add a release to the change metadata.

    :arg changes: Changes metadata to update
    :arg plugins: List of all plugin descriptions
    :arg fragments: List of all changelog fragments
    :arg version: The version for the new release
    :arg codename: The codename for the new release. Optional for collections
    :arg date: The release date
    """
    # make sure the version parses
    version_constructor = (semantic_version.Version if config.is_collection
                           else packaging.version.Version)
    version_constructor(version)

    LOGGER.info(
        'release version {} is a {} version', version,
        'release' if is_release_version(config, version) else 'pre-release')

    # filter out plugins which were not added in this release
    plugins = list(
        filter(
            lambda p: any([
                version.startswith('%s.' % p.version_added),
                version.startswith('%s-' % p.version_added
                                   ),  # needed for semver
                version.startswith('%s+' % p.version_added
                                   ),  # needed for semver
                version == p.version_added
            ]),
            plugins))

    changes.add_release(version, codename, date)

    for plugin in plugins:
        changes.add_plugin(plugin, version)

    fragments_added = []
    for fragment in fragments:
        if changes.add_fragment(fragment, version):
            fragments_added.append(fragment)

    changes.save()

    if not config.keep_fragments:
        for fragment in fragments_added:
            fragment.remove()
Exemplo n.º 2
0
def add_release(changes, plugins, fragments, version, codename, date):
    """Add a release to the change metadata.
    :type changes: ChangesMetadata
    :type plugins: list[PluginDescription]
    :type fragments: list[ChangelogFragment]
    :type version: str
    :type codename: str
    :type date: datetime.date
    """
    # make sure the version parses
    packaging.version.Version(version)

    LOGGER.info('release version %s is a %s version', version,
                'release' if is_release_version(version) else 'pre-release')

    # filter out plugins which were not added in this release
    plugins = list(
        filter(lambda p: version.startswith('%s.' % p.version_added), plugins))

    changes.add_release(version, codename, date)

    for plugin in plugins:
        changes.add_plugin(plugin.type, plugin.name, version)

    for fragment in fragments:
        changes.add_fragment(fragment.name, version)

    changes.save()
Exemplo n.º 3
0
    def _guess_conda_properties(self):
        conda_meta_path = self._conda_meta_path
        # Perhaps we should call "conda info --json" and parse it but for now we are going
        # to assume the default.
        conda_version = packaging.version.parse(CONDA_VERSION)
        conda_build_available = False
        miniconda_version = "3"

        if os.path.exists(conda_meta_path):
            for package in os.listdir(conda_meta_path):
                package_parts = package.split("-")
                if len(package_parts) < 3:
                    continue
                package = '-'.join(package_parts[:-2])
                version = package_parts[-2]
                # build = package_parts[-1]
                if package == "conda":
                    conda_version = packaging.version.parse(version)
                if package == "python" and version.startswith("2"):
                    miniconda_version = "2"
                if package == "conda-build":
                    conda_build_available = True

        self._conda_version = conda_version
        self._miniconda_version = miniconda_version
        self._conda_build_available = conda_build_available
Exemplo n.º 4
0
    def _guess_conda_properties(self):
        conda_meta_path = self._conda_meta_path
        # Perhaps we should call "conda info --json" and parse it but for now we are going
        # to assume the default.
        conda_version = packaging.version.parse(CONDA_VERSION)
        conda_build_available = False
        miniconda_version = "3"

        if os.path.exists(conda_meta_path):
            for package in os.listdir(conda_meta_path):
                package_parts = package.split("-")
                if len(package_parts) < 3:
                    continue
                package = '-'.join(package_parts[:-2])
                version = package_parts[-2]
                # build = package_parts[-1]
                if package == "conda":
                    conda_version = packaging.version.parse(version)
                if package == "python" and version.startswith("2"):
                    miniconda_version = "2"
                if package == "conda-build":
                    conda_build_available = True

        self._conda_version = conda_version
        self._miniconda_version = miniconda_version
        self._conda_build_available = conda_build_available
Exemplo n.º 5
0
def is_stable_version(version):
    """ Heuristic for whether this is the latest stable release """
    if not version.startswith("v"):
        return False  # branch name
    if "-" in version:
        return False  # prerelease tag

    git_out = subprocess.run(["git", "tag", "-l"],
                             capture_output=True,
                             check=True)

    versions = [v.strip() for v in git_out.stdout.decode("utf-8").split("\n")]
    versions = [v for v in versions
                if re.match(r"^v[\d\.]+$", v)]  # include vX.Y.Z only

    versions = [packaging.version.parse(v) for v in versions]

    max_version = max(versions)

    if max_version.public != version[1:]:
        print("Stable version is v{}. This version is {}.".format(
            max_version.public, version))
        return False
    else:
        print("This version {} is the stable version".format(version))
        return True
Exemplo n.º 6
0
    def __init__(self, version):
        """
        Initialize a new Version.

        Parameters:
            version: str, Version
                The semver-formatted version string; or another Version instance.
        """
        if isinstance(version, Version):
            version = str(version)
        if not isinstance(version, str):
            raise TypeError("version")

        #support versions such as: "application/vnd.mds.provider+json;version=0.3"
        if version.startswith('application/vnd.mds.provider+json;version='):
            version = version.split('=')[1]

        self._version = self._parse(version)
        self._legacy = None

        if isinstance(self._version, packaging.version.LegacyVersion):
            # versions like "0.3.x" or "0.x"
            try:
                # assume the highest PATCH support
                major, minor, legacy = str(self._version).split(".")
                self._version = self._parse(f"{major}.{minor}.{sys.maxsize}")
                # note the highest valid version tuple index, and the "legacy" data
                self._legacy = (1, legacy)
            except:
                # assume the highest MINOR.PATCH support
                major, legacy = str(self._version).split(".")
                self._version = self._parse(
                    f"{major}.{sys.maxsize}.{sys.maxsize}")
                # note the highest valid version tuple index, and the "legacy" data
                self._legacy = (0, legacy)
        elif len(self.tuple) < 2:
            # MAJOR only versions like "0", "1"
            self._version = self._parse(
                f"{self.tuple[0]}.{sys.maxsize}.{sys.maxsize}")
            self._legacy = (0, None)
        elif len(self.tuple) < 3:
            # MAJOR.MINOR only version like "0.3"
            self._version = self._parse(
                f"{self.tuple[0]}.{self.tuple[1]}.{sys.maxsize}")
            self._legacy = (1, None)
Exemplo n.º 7
0
def get_versions_by_regex_for_text(text, url, regex, project):
    ''' For the provided text, return all the version retrieved via the
    specified regular expression.

    '''

    try:
        upstream_versions = list(set(re.findall(regex, text)))
    except sre_constants.error:  # pragma: no cover
        raise AnityaPluginException("%s: invalid regular expression" %
                                    project.name)

    for index, version in enumerate(upstream_versions):

        # If the version retrieved is a tuple, re-constitute it
        if type(version) == tuple:
            version = ".".join([v for v in version if not v == ""])

        # Strip the version_prefix early
        if project.version_prefix is not None and \
                version.startswith(project.version_prefix):
            version = version[len(project.version_prefix):]
        upstream_versions[index] = version

        if " " in version:
            raise AnityaPluginException(
                "%s: invalid upstream version:>%s< - %s - %s " %
                (project.name, version, url, regex))
    if len(upstream_versions) == 0:
        raise AnityaPluginException(
            "%(name)s: no upstream version found. - %(url)s -  "
            "%(regex)s" % {
                'name': project.name,
                'url': url,
                'regex': regex
            })

    return upstream_versions
Exemplo n.º 8
0
def is_stable_version(version):
    """ Heuristic for whether this is the latest stable release """
    if not version.startswith('v'):
        return False  # branch name
    if '-' in version:
        return False  # prerelease tag

    git_out = subprocess.check_output(['git', 'tag', '-l']).decode('utf-8')

    versions = [v.strip() for v in git_out.split('\n')]
    versions = [v for v in versions
                if re.match(r'^v[\d\.]+$', v)]  # include vX.Y.Z only

    versions = [packaging.version.parse(v) for v in versions]

    max_version = max(versions)

    if max_version.public != version[1:]:
        print('Stable version is v{}. This version is {}.'.format(
            max_version.public, version))
        return False
    else:
        print('This version {} is the stable version'.format(version))
        return True