コード例 #1
0
ファイル: utils.py プロジェクト: U0001F3A2/golem
def get_version_spec(ours_v: semantic_version.Version) \
        -> semantic_version.Spec:
    spec_str = '>={major}.{minor}.0,<{next_minor}'.format(
        major=ours_v.major,
        minor=ours_v.minor,
        next_minor=ours_v.next_minor(),
    )
    spec = semantic_version.Spec(spec_str)
    return spec
コード例 #2
0
ファイル: template.py プロジェクト: wyatt88/estate
 def update(self, instance, validated_data):
     version_increment = validated_data.pop("version_increment", "patch")
     if version_increment == "initial":
         raise exceptions.APIException("Unable to update template with version_increment set to 'initial'!")
     v = Version(instance.version)
     if version_increment == "major":
         validated_data["version"] = str(v.next_major())
     if version_increment == "minor":
         validated_data["version"] = str(v.next_minor())
     if version_increment == "patch":
         validated_data["version"] = str(v.next_patch())
     validated_data["dependencies"] = []
     return super(TemplateSerializer, self).update(instance, validated_data)
コード例 #3
0
def best_upgrade(current: Version,
                 candidates: List[Version],
                 track: str = 'MajorVersion'):
    if track == 'PatchLevel':
        spec = Spec('>{current},<{next_minor}'.format(
            current=str(current), next_minor=str(current.next_minor())))
    elif track == 'MinorVersion':
        spec = Spec('>{current},<{next_minor}'.format(
            current=str(current), next_minor=str(current.next_major())))
    elif track == 'MajorVersion':
        spec = Spec('>{current}'.format(current=str(current)))
    else:
        raise ValueError('unsupported "track": {track}'.format(track=track))
    return spec.select(candidates)
コード例 #4
0
def get_next_version(release_type):
    """Increment a version for a particular release type."""
    if not isinstance(release_type, ReleaseType):
        raise TypeError()

    version = Version(get_current_version())

    if release_type is ReleaseType.major:
        return str(version.next_major())

    if release_type is ReleaseType.minor:
        return str(version.next_minor())

    return str(version.next_patch())
コード例 #5
0
def update_version_number(update_level='patch'):
    """Update version number

    Returns a semantic_version object"""

    """Find current version"""
    temp_file = version_file().parent / ("~" + version_file().name)
    with open(str(temp_file), 'w') as g:
        with open(str(version_file()), 'r') as f:
            for line in f:
                version_matches = bare_version_re.match(line)
                if version_matches:
                    bare_version_str = version_matches.groups(0)[0]
                    if semantic_version.validate(bare_version_str):
                        current_version = Version(bare_version_str)
                        print("{}Current version is {}".format(" "*4, current_version))
                    else:
                        current_version = Version.coerce(bare_version_str)
                        if not text.query_yes_quit("{}I think the version is {}. Use it?".format(" "*4, current_version), default="yes"):
                            exit(colorama.Fore.RED + 'Please set an initial version number to continue')

                    """Determine new version number"""
                    if update_level is 'major':
                        current_version = current_version.next_major()
                    elif update_level is 'minor':
                        current_version = current_version.next_minor()
                    elif update_level is 'patch':
                        current_version = current_version.next_patch()
                    elif update_level is 'prerelease':
                        if not current_version.prerelease:
                            current_version = current_version.next_patch()
                            current_version.prerelease = ('dev', )
                    elif update_level is None:
                        # don't update version
                        pass
                    else:
                        exit(colorama.Fore.RED + 'Cannot update version in {} mode'.format(update_level))

                    print("{}New version is     {}".format(" "*4, current_version))

                    """Update version number"""
                    line = '__version__ = "{}"\n'.format(current_version)
                print(line, file=g, end="")
        #print('', file=g)  # add a blank line at the end of the file
    shutil.copyfile(str(temp_file), str(version_file()))
    os.remove(str(temp_file))
    return(current_version)
コード例 #6
0
ファイル: tasks.py プロジェクト: MinchinWeb/colourettu
def update_version_number(update_level='patch'):
    """Update version number

    Returns a semantic_version object"""

    """Find current version"""
    temp_file = version_file().parent / ("~" + version_file().name)
    with open(str(temp_file), 'w') as g:
        with open(str(version_file()), 'r') as f:
            for line in f:
                version_matches = bare_version_re.match(line)
                if version_matches:
                    bare_version_str = version_matches.groups(0)[0]
                    if semantic_version.validate(bare_version_str):
                        current_version = Version(bare_version_str)
                        print("{}Current version is {}".format(" "*4, current_version))
                    else:
                        current_version = Version.coerce(bare_version_str)
                        if not text.query_yes_quit("{}I think the version is {}. Use it?".format(" "*4, current_version), default="yes"):
                            exit(colorama.Fore.RED + 'Please set an initial version number to continue')

                    """Determine new version number"""
                    if update_level is 'major':
                        current_version = current_version.next_major()
                    elif update_level is 'minor':
                        current_version = current_version.next_minor()
                    elif update_level is 'patch':
                        current_version = current_version.next_patch()
                    elif update_level is 'prerelease':
                        if not current_version.prerelease:
                            current_version = current_version.next_patch()
                            current_version.prerelease = ('dev', )
                    elif update_level is None:
                        # don't update version
                        pass
                    else:
                        exit(colorama.Fore.RED + 'Cannot update version in {} mode'.format(update_level))

                    print("{}New version is     {}".format(" "*4, current_version))

                    """Update version number"""
                    line = '__version__ = "{}"\n'.format(current_version)
                print(line, file=g, end="")
        #print('', file=g)  # add a blank line at the end of the file
    shutil.copyfile(str(temp_file), str(version_file()))
    os.remove(str(temp_file))
    return(current_version)
コード例 #7
0
    def _normalize(self, constraint):
        """
        Normalizes the constraint so that it can be understood
        by the underlying system.
        
        :param constraint: The dependency constraint.
        :type constraint: str or dict
        
        :rtype: str
        """
        if self.is_vcs_dependency():
            # Any VCS dependency is considered prerelease
            self._is_prerelease = True

            return self._normalize_vcs_constraint(constraint)

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

        constraint = self._spec(version)
        normalized = []

        for spec in constraint.specs:
            version = spec.spec

            if VersionParser.parse_stability(version) == 'dev':
                self._accepts_prereleases = True

            major, minor, patch, prerelease = (version.major, version.minor,
                                               version.patch,
                                               version.prerelease)
            current = '{}.{}.{}'.format(major, minor or 0, patch or 0)
            current = Version(current)

            if spec.kind == SpecItem.KIND_CARET:
                if current.major != 0 or minor is None:
                    upper = current.next_major()
                elif current.minor != 0 or patch is None:
                    upper = current.next_minor()
                else:
                    upper = current.next_patch()

                if prerelease:
                    current = str(current) + '{}'.format(''.join(prerelease))

                normalized.append('>={},<{}'.format(current, upper))
            elif spec.kind == SpecItem.KIND_TILDE:
                if minor is None and patch is None:
                    upper = current.next_major()
                else:
                    upper = current.next_minor()

                upper = '{}.{}.{}'.format(*upper)

                normalized.append('>={},<{}'.format(current, upper))

                if prerelease:
                    current = str(current) + '{}'.format(''.join(prerelease))
            else:
                current = spec.kind + str(current)
                if prerelease:
                    current += '{}'.format(''.join(prerelease))

                normalized.append(current)

        return ','.join(normalized)
import sys
from pathlib import Path
from semantic_version import Version

# Assume this script is called from the root directory

version_path = Path('src/resources/version.txt')
v = Version(version_path.read_text())

increment_type = sys.argv[1]
if increment_type == 'major':
    v = v.next_major()
elif increment_type == 'minor':
    v = v.next_minor()
elif increment_type == 'patch':
    v = v.next_patch()
else:
    raise ValueError(f'Increment type should be "major", "minor", or '
                     f'"patch", but was {increment_type}')

version_path.write_text(str(v))