def bump_tag_version(repo, current_version, selection=None): """Bump the tag version using semantic versioning.""" current_version = current_version.replace("v", "") while True: if not selection: print '----------------------------------------\n' print '0: Bump major version {} -> {} \n'.format( current_version, semver.bump_major(current_version)) print '1: Bump minor version {} -> {} \n'.format( current_version, semver.bump_minor(current_version)) print '2: Bump patch version {} -> {} \n'.format( current_version, semver.bump_patch(current_version)) selection = raw_input( "Choose version number component to increment: ") if selection == "0" or selection == "major": return "v" + semver.bump_major(current_version) break elif selection == "1" or selection == "minor": return "v" + semver.bump_minor(current_version) break elif selection == "2" or selection == "patch": return "v" + semver.bump_patch(current_version) break else: print "Invalid selection. Please make a valid selection." selection = None
def add_covers(self): new_covers = [] comment = '' for cover in self.meta.covers: #check that the covers are in repo cover_path = os.path.join(self.local_path, cover.get("image_path", "")) if os.path.isfile(cover_path): new_covers.append(cover) if len(new_covers) == 0: cover_files = self.local_repo.cover_files() if self.local_repo else [] if cover_files: new_covers.append( {"image_path": cover_files[0], "cover_type":"archival"} ) comment = "Added archival cover. " else: with open('{}/cover.png'.format(self.local_path), 'wb+') as cover: self.generate_cover().save(cover) new_covers.append( {"image_path": "cover.png", "cover_type":"generated"} ) comment = "Generated cover. " if '_version' in self.meta.metadata: self.meta.metadata['_version'] = semver.bump_minor(self.meta._version) else: self.meta.metadata['_version'] = '0.1.0' self.meta.metadata['covers'] = new_covers return comment
def _get_version(self) -> VersionInfo: hook_result = self.hooks.get_version()() proposed_version = VersionInfo.parse(hook_result.strip()) print(f"Current version: {proposed_version}") if self.require_creation_of_release_branch: proposed_version = VersionInfo.parse( bump_minor(str(proposed_version))) if self.require_creation_of_hotfix_branch: proposed_version = VersionInfo.parse( bump_patch(str(proposed_version))) if self.no_input: return proposed_version version = None while version is None: user_input = input(f"Input version to use [{proposed_version}]: ") if user_input: try: version = VersionInfo.parse(user_input) except ValueError as exc: print(exc) continue else: version = proposed_version return version
def _get_new_version_number(self): try: self.last_tag = self.git.describe("--tags", abbrev=0) except GitCommandError as e: logging.debug('impossible to retrieve tags: {}'.format(e)) logging.warning( 'impossible to retrieve tags, we assume there is none') self.last_tag = '0.0.0' # some tags might have a leading 'v', we remove it to get a real semver last_tag = self.last_tag.strip('v') logging.debug("tag = {}".format(last_tag)) if self.release_type == 'major': return semver.bump_major(last_tag) elif self.release_type == 'minor': return semver.bump_minor(last_tag) elif self.release_type == 'hotfix': # TODO I think we can do better stuff for hotfixes and automatically merge some PR passed as # arguments # too early to do anything then logging.fatal( "hotfixes are not implemented yet, it's open source you're welcome to do it" ) exit(2) #return semver.bump_hotfix(last_tag) else: logging.fatal('{} is not a known release type'.format( self.release_type)) exit(2)
def add_covers(self): new_covers = [] comment = '' for cover in self.meta.covers: #check that the covers are in repo cover_path = os.path.join(self.local_path, cover.get("image_path", "")) if os.path.isfile(cover_path): new_covers.append(cover) if len(new_covers) == 0: cover_files = self.local_repo.cover_files( ) if self.local_repo else [] if cover_files: new_covers.append({ "image_path": cover_files[0], "cover_type": "archival" }) comment = "Added archival cover. " else: with open('{}/cover.png'.format(self.local_path), 'wb+') as cover: self.generate_cover().save(cover) new_covers.append({ "image_path": "cover.png", "cover_type": "generated" }) comment = "Generated cover. " if '_version' in self.meta.metadata: self.meta.metadata['_version'] = semver.bump_minor( self.meta._version) else: self.meta.metadata['_version'] = '0.1.0' self.meta.metadata['covers'] = new_covers return comment
def bump(latest): merge_request_id = extract_merge_request_id_from_commit() labels = retrieve_labels_from_merge_request(merge_request_id) new_version = None print('MR Labels', labels) if "bump-major" in labels: print('Bump major') new_version = semver.bump_major(latest) elif "bump-minor" in labels: print('Bump minor') new_version = semver.bump_minor(latest) elif "bump-patch" in labels: print('Bump patch') new_version = semver.bump_patch(latest) elif "finalize-rc" in labels: print('Finalize rc') new_version = semver.finalize_version(latest) elif "bump-build": print('Bump build') new_version = semver.bump_build(new_version if new_version else latest) if "bump-rc" in labels and not "finalize-rc" in labels: print('Bump rc') new_version = semver.bump_prerelease( new_version if new_version else latest) new_version = semver.bump_build(new_version) return new_version if new_version else latest
def version_from_git_tag(project, logger): """ Set project version according git tags""" # get git info tags, last_commit, repo_is_dirty = _get_repo_info( project.get_property('semver_git_tag_repo_dir') if project. get_property('semver_git_tag_repo_dir') else project.basedir) # get last tag which satisfies SemVer last_semver_tag = None semver_regex = semver._REGEX # pylint: disable=protected-access tag_list = [] for tag in reversed(tags): tag_list.append(tag.name) logger.debug("All git tags: %s." % ','.join(tag_list)) for tag in reversed(tags): match = semver_regex.match(tag.name) if match: if ((not last_semver_tag) or (semver.compare(tag.name, last_semver_tag.name) == 1)): last_semver_tag = tag if not last_semver_tag: logger.warn("No SemVer git tag found. " "Consider removing plugin pybuilder_semver_git_tag.") return else: logger.info("Found SemVer tag: %s" % last_semver_tag.name) # get last commit for HEAD # if dirty or last commit isn't equal last tag commit # - increase version and add .dev if last_commit != last_semver_tag.commit or repo_is_dirty: if repo_is_dirty: logger.debug("Repo is marked as dirty - use dev version.") else: logger.debug("Last tag %s has commit %s, " "but last commit is %s - use dev version." % (last_semver_tag.name, str( last_semver_tag.commit), str(last_commit))) increase_part = project.get_property('semver_git_tag_increment_part') if increase_part == 'major': project.version = _add_dev(semver.bump_major(last_semver_tag.name)) elif increase_part == 'minor': project.version = _add_dev(semver.bump_minor(last_semver_tag.name)) elif increase_part == 'patch': project.version = _add_dev(semver.bump_patch(last_semver_tag.name)) else: raise BuildFailedException( "Incorrect value for `semver_git_tag_increment_part` property. " "Has to be in (`major`, `minor`, `patch`), but %s passed." % project.get_property('semver_git_tag_increment_part')) # if not dirty and last commit is equal last tag commit # - it's release tag else: project.version = last_semver_tag.name # DISTRIBUTION_PROPERTY is also be affected project.set_property( DISTRIBUTION_PROPERTY, "$dir_target/dist/{0}-{1}".format(project.name, project.version)) logger.info( "Project version was changed to: %s, dist_version: %s, %s: %s" % (project.version, project.dist_version, DISTRIBUTION_PROPERTY, project.get_property(DISTRIBUTION_PROPERTY)))
def bump_version(version, increment_type): if increment_type == 'major': return semver.bump_major(version) elif increment_type == 'minor': return semver.bump_minor(version) elif increment_type == 'patch': return semver.bump_patch(version)
def _prepare_repo(repo_class, repo_path, mocker, monkeypatch, caplog): with caplog.at_level(logging.ERROR): # Set log level to avoid to overcharge logs with GitPython logs # Initialize repository for testing repo = repo_class.init(path=repo_path) # Monkey patch and Mock _repo.git.push function so we do not need to effectively push to remotes during tests. # We cannot patch the git.push function due to GitPython implementation of Git class with __slots__ # (c.f. https://github.com/gitpython-developers/GitPython/blob/master/git/cmd.py) # So we need to monkey path the full _repo.git attribute class MockGit(Git): def push(self, *args, **kwargs): pass monkeypatch.setattr(repo, 'git', value=MockGit(repo.working_dir)) mocker.patch.object(repo.git, 'push') # Add files, commits and tags to the repository version = '0.0.0' for i, file in enumerate(repo.untracked_files): repo.git.add(file) repo.git.commit(file, '-m', 'add {file}'.format(file=file)) if i % 2 == 0: repo.create_tag('v{version}'.format(version=version), message='Release v{version}'.format(version=version)) if i > 0 and i % 8 == 0: version = semver.bump_major(version) elif i > 0 and i % 4 == 0: version = semver.bump_minor(version) else: version = semver.bump_patch(version) repo.create_remote('origin', '[email protected]:nmvalera/boilerplate-python.git') return repo
def bump(self, major=None, minor=None, patch=None, status=None, build=None): """Bump the version.""" # Number positions are mutually exclusive. if major: self._current = semver.bump_major(self._original) elif minor: self._current = semver.bump_minor(self._original) elif patch: self._current = semver.bump_patch(self._original) else: self._current = self._original # Set the status. if status: self._current += "-%s" % status elif self.object.prerelease: self._current += "-%s" % self.object.prerelease else: pass # Set the build. if build: self._current += "+%s" % build elif self.object.build: self._current += "+%s" % self.object.build else: pass self.object = semver.parse_version_info(self._current)
def version_bump(ctx, major=False, minor=False, patch=False, version=''): """Makes the version bump in the required files""" import semver f = open("VERSION", "r") fversion = f.readline().strip('\n') f.close() if version: nversion = version else: version = fversion if major: nversion = semver.bump_major(version) elif minor: nversion = semver.bump_minor(version) elif patch: nversion = semver.bump_patch(version) else: print("No version change") print("Old version {} New version {}".format(fversion, nversion)) ctx.run("sed -i -e 's/:version: .*/:version: {}/' README.rst".format(nversion)) f = open("VERSION", "w") f.write(nversion) f.close()
def bump(latest): commit_message = git('show-branch', '--no-name', 'HEAD') if re.search(r'\[bump major\]', commit_message): return semver.bump_major(latest) if re.search(r'\[bump minor\]', commit_message): return semver.bump_minor(latest) return semver.bump_patch(latest)
def next_version(self): """ Based on the changelog, calculate what the next version would be. This is done by iterating over all issues in order and incrementing the version number according to each issue version modifier. Returns: str: The semantic version string """ result = self._current_version self._debug('Determining next version...') for issue in self._sort(self.all_issues, reverse=False): if issue.version_modifier == ChangelogIssue.PATCH: result = semver.bump_patch(result) if issue.version_modifier == ChangelogIssue.MINOR: result = semver.bump_minor(result) if issue.version_modifier == ChangelogIssue.MAJOR: result = semver.bump_major(result) self._debug('Applied issue on incremental result.', issue_title=issue.title, result=result, version_modifier=issue.version_modifier) result = None if result == self._current_version else result self._debug('Determined next version.', next_version=result) return result
def update_metadata(metadata, version_increment, provider, checksum, serve_local): """ Update the Vagrant box metadata. :param metadata: metadata to update :param version_increment: how to increment the version :param provider: for which provider to update the metadata :param checksum: new checksum for the box data :param serve_local: whether or not to serve the box locally :return: updated metadata :rtype: dict """ if version_increment == 'major': metadata['version'] = bump_major(metadata['version']) elif version_increment == 'minor': metadata['version'] = bump_minor(metadata['version']) elif version_increment == 'patch': metadata['version'] = bump_patch(metadata['version']) current_provider_data = None for provider_data in metadata['providers']: if provider_data['name'] == provider: current_provider_data = provider_data break current_provider_data['checksum'] = checksum if serve_local: current_provider_data['url'] = serve_local return metadata
def _get_new_version_number(self): try: self.last_tag = self.git.describe("--tags", abbrev=0) except GitCommandError as e: logging.debug('impossible to retrieve tags: {}'.format(e)) logging.warning('impossible to retrieve tags, we assume there is none') self.last_tag = '0.0.0' # some tags might have a leading 'v', we remove it to get a real semver last_tag = self.last_tag.strip('v') logging.debug("tag = {}".format(last_tag)) if self.release_type == 'major': return semver.bump_major(last_tag) elif self.release_type == 'minor': return semver.bump_minor(last_tag) elif self.release_type == 'hotfix': # TODO I think we can do better stuff for hotfixes and automatically merge some PR passed as # arguments # too early to do anything then logging.fatal("hotfixes are not implemented yet, it's open source you're welcome to do it") exit(2) #return semver.bump_hotfix(last_tag) else: logging.fatal('{} is not a known release type'.format(self.release_type)) exit(2)
def main(): if len(sys.argv) < 2: error("Pass in plugin type as the first argument. " "Choose from: {}".format(PLUGIN_TYPES)) elif len(sys.argv) < 3: error("You must also pass in repository SHA as the argument") repo_type = sys.argv[1].lower() if repo_type == "sublime": repo_url = SUBLIME_REPO elif repo_type == "vim": repo_url = VIM_REPO elif repo_type == "nvim": repo_url = NVIM_REPO else: error( "Please pass in one of {} as the plugin type".format(PLUGIN_TYPES)) master_SHA = sys.argv[2] bot_username = os.environ.get("RELEASE_BOT_USERNAME") bot_password = os.environ.get("RELEASE_BOT_PASSWORD") g = Github(bot_username, bot_password) release_repo = None for repo in g.get_organization(ORG_NAME).get_repos(): if repo.html_url == repo_url: release_repo = repo break if release_repo is None: error("{} repo not found".format(repo_type)) tags = release_repo.get_tags() last_tag = None for t in tags: last_tag = t break if (last_tag is None): last_tag = '0.0.0' else: if last_tag.commit.sha == master_SHA: error("Cannot create release with same SHA") last_tag = last_tag.name tag = semver.bump_minor(last_tag) release_repo.create_git_tag_and_release( tag, "Release version {}".format(tag), "v{}".format(tag), "Release version {}".format(tag), master_SHA, "commit", ) print("Succesfully created release v{}".format(tag))
def minor(): v = get_version() nv = semver.bump_minor(v) if options["human"]: click.echo("{} -> {}".format(v, nv)) else: click.echo(nv) write_version(nv)
def transform_special_version(special_version: str, previous_version: str) -> str: if special_version in ["patch", "p"]: return semver.bump_patch(previous_version) elif special_version in ["minor", "m"]: return semver.bump_minor(previous_version) elif special_version in ["major", "M"]: return semver.bump_major(previous_version) else: raise "Unreachable: `transform_special_version` should never be called with invalid special version"
def test_version_is_newer(requests): newer_version = semver.bump_minor(__version__) requests.get.return_value = FakeResponse( 200, "http://someplace/releases/tags/{t}".format(t=newer_version) ) latest_version = check_newer_version() assert latest_version == newer_version
def test_version_is_newer(requests): newer_version = semver.bump_minor(__version__) requests.get.return_value = FakeResponse( 200, "http://someplace//usage/latest/", {"version": __version__, "up_to_date": False} ) latest_version = check_newer_version(command="init") assert latest_version == __version__
def bump(latest): merge_request_id = extract_merge_request_id_from_commit() labels = retrieve_labels_from_merge_request(merge_request_id) if "bump-minor" in labels: return semver.bump_minor(latest) elif "bump-major" in labels: return semver.bump_major(latest) else: return semver.bump_patch(latest)
def bump(latest): merge_request = get_last_merge_request() labels = merge_request.labels if "bump-minor" in labels: return semver.bump_minor(latest) elif "bump-major" in labels: return semver.bump_major(latest) else: return semver.bump_patch(latest)
def main(): """ Main method. This method holds what you want to execute when the script is run on command line. """ args = get_arguments() setup_logging(args) version_path = os.path.abspath(os.path.join( os.path.dirname(__file__), '..', '..', '.VERSION' )) try: version_text = open(version_path).read().strip() except Exception: print ('Could not open or read the .VERSION file') sys.exit(1) try: semver.parse(version_text) except ValueError: print ('The .VERSION file contains an invalid version: "{0}"'.format( version_text )) sys.exit(1) new_version = version_text if args.version: try: if semver.parse(args.version): new_version = args.version except Exception: print ('Could not parse "{0}" as a version'.format( args.version )) sys.exit(1) elif args.bump_major: new_version = semver.bump_major(version_text) elif args.bump_minor: new_version = semver.bump_minor(version_text) elif args.bump_patch: new_version = semver.bump_patch(version_text) try: with open(version_path, 'w') as version_file: version_file.write(new_version) except Exception: print ('Could not write the .VERSION file') sys.exit(1) print new_version
def bump_version(current: str, major: bool = False, minor: bool = False, patch: bool = False): if major: return semver.bump_major(current) if minor: return semver.bump_minor(current) if patch: return semver.bump_patch(current) return current
def bump_version(latest): merge_request_id = extract_merge_request_id_from_commit() labels = retrieve_labels_from_merge_request(merge_request_id) if "bump::major" in str(labels): bump = semver.bump_major(latest) elif "bump::minor" in str(labels): bump = semver.bump_minor(latest) else: bump = semver.bump_patch(latest) return bump
def release(self, release_type, local_template, current_version): product_version = current_version if release_type == 'build': product_version = semver.bump_build(current_version) if release_type == 'major': product_version = semver.bump_major(current_version) if release_type == 'minor': product_version = semver.bump_minor(current_version) if release_type == 'patch': product_version = semver.bump_patch(current_version) self.release_new_build(local_template, product_version)
def __addIncrementedTag(self) -> None: current_tag = self.__getLatestTag() if current_tag is None: tag = "1.0.0" else: tag = semver.bump_minor(current_tag) git.cmd.Git(self.workdir).tag([tag]) logger.debug(f"Added tag {tag} to current commit.") return None
def bump_version(component: str, version: str) -> str: sem_version = version.replace("v", "") bumped = "" if component == "major": bumped = semver.bump_major(sem_version) elif component == "minor": bumped = semver.bump_minor(sem_version) elif component == "patch": bumped = semver.bump_patch(sem_version) else: bumped = version return "v{}".format(bumped)
def new_version(bump_type, commit_hash): reload(app_info) template = Template(RELEASE_TEMPLATE) new_ver = app_info.version if bump_type == "major": new_ver = semver.bump_major(app_info.version) if bump_type == "minor": new_ver = semver.bump_minor(app_info.version) if bump_type == "patch": new_ver = semver.bump_patch(app_info.version) res = template.render({"version": new_ver, "commit_hash": commit_hash}) with open("caffeine/app_info.py", "w") as f: f.write(res)
def set_version_from_git_tag(project, logger): """ Set project version according git tags""" # get git info version_prefix = project.get_property('semver_git_tag_version_prefix') repo_path = _get_repo_path(project) tags, last_commit, repo_is_dirty = _get_repo_info(repo_path, version_prefix) tag_list = [] for tag in tags: tag_list.append(tag.name) logger.debug("All git tags: %s." % ','.join(tag_list)) # get last tag which satisfies SemVer last_semver_tag = _seek_last_semver_tag(tags) if not last_semver_tag: logger.warn("No SemVer git tag found. " "Consider removing plugin pybuilder_semver_git_tag.") return else: logger.info("Found SemVer tag: %s" % last_semver_tag.name) # get last commit for HEAD # if dirty or last commit isn't equal last tag commit # - increase version and add .dev if last_commit != last_semver_tag.commit or repo_is_dirty: if repo_is_dirty: logger.debug("Repo is marked as dirty - use dev version.") else: logger.debug("Last tag %s has commit %s, " "but last commit is %s - use dev version." % (last_semver_tag.name, str( last_semver_tag.commit), str(last_commit))) increase_part = project.get_property('semver_git_tag_increment_part') if increase_part == 'major': project.version = _add_dev(semver.bump_major(last_semver_tag.name)) elif increase_part == 'minor': project.version = _add_dev(semver.bump_minor(last_semver_tag.name)) elif increase_part == 'patch': project.version = _add_dev(semver.bump_patch(last_semver_tag.name)) else: raise BuildFailedException( "Incorrect value for `semver_git_tag_increment_part` property. " "Has to be in (`major`, `minor`, `patch`), but `%s` passed." % project.get_property('semver_git_tag_increment_part')) # if not dirty and last commit is equal last tag commit # - it's release tag else: project.version = last_semver_tag.name if project.get_property('semver_git_tag_changelog'): check_changelog(project.expand_path('$semver_git_tag_changelog'), repo_path, last_semver_tag, tags, logger) logger.info("Project version was set to: %s, dist_version: %s" % (project.version, project.dist_version))
def desugar_range_and_match(version, semver_range): if 'x' in semver_range: if len(semver_range.split('.')) < 3: range_floor = semver_range.replace('x', '0.0') range_ceiling = semver.bump_major(range_floor) else: range_floor = semver_range.replace('x','0') range_ceiling = semver.bump_minor(range_floor) if not semver.match(version, ">="+range_floor): return False if not semver.match(version, "<"+range_ceiling): return False return True
def bump(latest): minor_bump_label = os.environ.get("MINOR_BUMP_LABEL") or "bump-minor" major_bump_label = os.environ.get("MAJOR_BUMP_LABEL") or "bump-major" merge_request_id = extract_merge_request_id_from_commit() labels = retrieve_labels_from_merge_request(merge_request_id) if minor_bump_label in labels: return semver.bump_minor(latest) elif major_bump_label in labels: return semver.bump_major(latest) else: return semver.bump_patch(latest)
def main(): version_filepath = glob(os.path.join("src", "pymedphys*", "_version.py"))[0] package_name = os.path.split(os.path.dirname(version_filepath))[-1] with open('package.json', 'r') as file: data = json.load(file) semver_string = data['version'] loaded_version_info = semver_string.replace('.', ' ').replace('-', ' ').split(' ') version_info = [int(number) for number in loaded_version_info[0:3] ] + [''.join(loaded_version_info[3::])] # type: ignore __version__ = '.'.join(map(str, version_info[:3])) + ''.join( version_info[3:]) # type: ignore version_file_contents = textwrap.dedent("""\ version_info = {} __version__ = "{}" """.format(version_info, __version__)) with open(version_filepath, 'w') as file: file.write(version_file_contents) semver_parsed = semver.parse(semver_string) if semver_parsed['major'] == 0: upper_limit = semver.bump_minor(semver_string) npm_version_prepend = "~" else: upper_limit = semver.bump_major(semver_string) npm_version_prepend = "^" dependencies_filepath = os.path.join(ROOT, "dependencies.json") with open(dependencies_filepath, 'r') as file: dependencies_data = json.load(file) dependencies_data['pins']['pypi']['internal'][package_name] = ( ">= {}, < {}".format(__version__, upper_limit)) dependencies_data['pins']['npm']['internal'][package_name] = ( "{}{}".format(npm_version_prepend, semver_string)) with open(dependencies_filepath, 'w') as file: json.dump(dependencies_data, file, indent=2, sort_keys=True)
def main(): release_type = sys.argv[1] current_version = get_current_version() if release_type == "patch": release_version = semver.bump_patch(current_version) elif release_type == "minor": release_version = semver.bump_minor(current_version) elif release_type == "major": release_version = semver.bump_major(current_version) else: raise Exception("Please pick one patch/minor/major") update_version(release_version) sys.stdout.write(release_version)
def bump(self, major=False, minor=False, patch=False, status=None, build=None): # Get the current version as an instance. current_info = semver.parse_version_info(self.identifier) # Get the new version. if major: new_version = semver.bump_major(self.identifier) elif minor: new_version = semver.bump_minor(self.identifier) elif patch: new_version = semver.bump_patch(self.identifier) else: new_version = self.identifier # Update the status. if status: status = status elif current_info.prerelease: status = current_info.prerelease else: status = None if status: info = semver.parse_version_info(new_version) new_version = "%s.%s.%s-%s" % ( info.major, info.minor, info.patch, status ) # Update the build. if build: info = semver.parse_version_info(new_version) new_version = "%s.%s.%s-%s+%s" % ( info.major, info.minor, info.patch, info.prerelease, build ) # Return the new version. new_version = new_version.strip() return new_version
def next_tag(actual_tag, sim_tags, sim2actual, repo, ignorelist): last_tag = sim_tags[-1] runner = runtests.TestRunner( "test", repo=repo, cache="out/cache-"+actual_tag ) nf_viol, bc_viol = cvt(runner, sim_tags, actual_tag, semver.bump_patch(last_tag), sim2actual, ignorelist) if not nf_viol and not bc_viol: return semver.bump_patch(last_tag) elif not bc_viol: return semver.bump_minor(last_tag) else: return semver.bump_major(last_tag)
def match(version, spec): if version[0] == 'v': version = version[1:] if spec[0] == '^': base = spec[1:] parsed_base = semver.parse(base) if parsed_base['major'] > 0: top = semver.bump_major(base) elif parsed_base['minor'] > 0: top = semver.bump_minor(base) else: top = semver.bump_patch(base) return semver.match(version, ">="+base) and semver.match(version, "<="+top) else: try: return semver.match(version, spec) except ValueError: # this happens when the spec isn't an expression, in which case we need an exact match return semver.parse(version) == semver.parse(spec)
def main(): parser = argparse.ArgumentParser(description='judge your types') parser.add_argument('module', metavar='MODULE', default=None, help='module to import and check') parser.add_argument('version', nargs='?', metavar='VERSION', default=None, help='current version of the package') parser.add_argument('-o', '--out', default=None, help='save current type definitions to this file') parser.add_argument('-f', '--file', default=None, help='load type definitions from this file') args = parser.parse_args() sys.path.append(os.getcwd()) m = importlib.import_module(args.module) previous_types = None if args.file is not None: with open(args.file) as f: previous_types = json.load(f) types = represent_type_hints_module(m) if previous_types: judgement = judge(previous_types, types) if args.version: v = args.version if judgement == 0: v = semver.bump_patch(v) elif judgement == 1: v = semver.bump_minor(v) elif judgement == 2: v = semver.bump_major(v) print(v) else: print({0: 'patch', 1: 'minor', 2: 'major'}.get(judgement)) if args.out: if args.out != '-': with open(args.out, 'w') as f: json.dump(types, f, sort_keys=True, indent=4) else: print(json.dumps(types, sort_keys=True, indent=4))
print "patched {}".format(app) request = json.loads(self.request.body) if app not in self.apps: self.set_status(404) self.finish() return ver = request["slug_uri"].split("_")[1].rstrip(".tgz") self.apps[app]["ver"] = ver self.apps[app]["state"] = "deploying" reactor.callLater(random.randint(0, 10), self.apps[app].__setitem__, "state", random.choice(["healthy", "unhealthy"])) if __name__ == "__main__": try: port = int(sys.argv[1]) except IndexError: port = 8888 for stage_num in xrange(0, 2): stage_port = port + stage_num application = cyclone.web.Application([ (r"/apps/", AppsHandler, dict(apps={k: v for k, v in apps.items()})), (r"/apps/(.*)", AppHandler, dict( apps={k: dict(v.items() + {"ver": semver.bump_minor(v["ver"]) if stage_num > 0 else v["ver"]}.items()) for k, v in apps.items()})) ]) log.startLogging(sys.stdout) reactor.listenTCP(stage_port, application) reactor.run()
def test_should_bump_minor(self): self.assertEqual(bump_minor('3.4.5'), '3.5.0')
def _version_bump_minor(value): return semver.bump_minor(value)
parser = argparse.ArgumentParser(description='Version bumper') parser.add_argument('-b','--bump', dest='bump', action='store', choices={'major','minor','patch'}, default='patch', help='defaults to %(default)s') args = parser.parse_args() verfile='bprc/_version.py' if args.bump == 'major': newver=semver.bump_major(__version__) if args.bump == 'minor': newver=semver.bump_minor(__version__) if args.bump == 'patch': newver=semver.bump_patch(__version__) # check if there are any unstaged changes. if there are, then exit from subprocess import call, run, PIPE result=run('expr $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l)', shell=True, universal_newlines=True, stdout=PIPE) if int(result.stdout) > 0: print("There are unstaged changes. Please fix, and re-run.") sys.exit(1) print('Git status is clean. Incrementing version number in' + verfile) print('New version is ' + newver)
def version_bump_minor(context, value): return semver.bump_minor(value)
def main(): p = argparse.ArgumentParser() p.add_argument("--strict", action="store_true", help="Run the simulation with strict bumping") p.add_argument("--repository", "-r", help="Path to repository on the system.") p.add_argument("--verbose", "-v", action="count") p.add_argument("--ignore-file") args = p.parse_args() if args.verbose == 1: logging.basicConfig(level=logging.INFO) if args.verbose == 2: logging.basicConfig(level=logging.DEBUG) tags = [ "1.0.1", "1.0.2", "1.0.3", "1.1.0", "1.2.0", "1.2.1", "1.2.2", "1.21.2", "1.21.3", "1.21.4", "1.21.5", "1.3.0", "1.3.1", "1.3.2", "1.4.0", "1.4.1", "1.4.2", "1.5.0", "1.6.0", "1.7.0", "1.7.1", "1.7.2", "1.7.3", "1.7.4", "1.8.0", "1.8.1", "1.8.2", "1.9.0", "1.10.0", "1.11.0", "1.12.0", "1.12.1", "1.13.0", "1.14.0", "1.15.0", "1.15.1", "1.16.0", "1.16.1", "1.16.2", "1.17.0", "1.17.1", "1.18.0", "1.18.1", "1.18.2", "1.19.0", "1.20.0", "1.20.1", "1.21.0", "1.21.1", "2.0.0", "2.0.1", "2.1.0", "2.2.0", "2.2.1", "2.2.2", "2.2.3", "2.2.4", "2.2.5", "2.3.0", "v2.3.1", "v2.3.2", "v2.3.3", "2.3.4", "v2.4.1", "v2.4.2", "v2.4.3", "v2.4.4", "v2.4.5", "v2.5.0", "v2.5.1", "v2.5.2", "v2.5.3" ] tags = semver.sort(tags) repo = git.Repository(args.repository) if not repo.is_repo(): error("Not currently in a git repository") ignorelist = [] if args.ignore_file: with open(args.ignore_file, 'r') as f: for line in f: ignorelist.append(line.strip()) # actual2sim = { "1.0.0": "1.0.0" } sim2actual = { "1.0.0": "1.0.0" } sim_tags = [ "1.0.0" ] last_sim_tag = "1.0.0" last_actual_tag = "1.0.0" for actual_tag in tags: logging.info("Actual tag: %s", actual_tag) next_tag = simtag.next_tag(actual_tag, sim_tags, sim2actual, repo, ignorelist) if args.strict: if semver.cmp(actual_tag, next_tag) == 1: # v1 < v2 logging.info("actual greater, bump to %s", actual_tag) next_tag = actual_tag else: actual_diff = semver.diff(last_actual_tag, actual_tag) if actual_diff > semver.diff(last_sim_tag, next_tag): if actual_diff == 3: next_tag = semver.bump_major(last_sim_tag) logging.info("actual did major, bump to %s", next_tag) elif actual_diff == 2: next_tag = semver.bump_minor(last_sim_tag) logging.info("actual did minor, bump to %s", next_tag) logging.info("Next tag: %s", next_tag) sim_tags.append(next_tag) sim2actual[next_tag] = actual_tag last_actual_tag = actual_tag last_sim_tag = next_tag print "A{},S{}".format(sim2actual[next_tag], next_tag)
def test_should_bump_minor(): assert bump_minor('3.4.5') == '3.5.0'
rpc_release_semver = re.sub('^r', '', rpc_release) # If the rpc_rc_release and rpc_release versions match, # then we need to increment the value of rpc_release. if rpc_rc_release == rpc_release: # If the current version is a prerelease version, # then increment the prerelease. rpc_release_parts = semver.parse(rpc_release_semver) if rpc_release_parts['prerelease'] is not None: rpc_release_semver_new = semver.bump_prerelease(rpc_release_semver) # Otherwise, this is a standard release and we # just need to do a minor version increment. else: rpc_release_semver_new = semver.bump_minor(rpc_release_semver) # Now add the 'r' prefix back on for the final version rpc_release = "r" + rpc_release_semver_new # Adjust the maas release release_data['maas_release'] = maas_release # Adjust the OSA SHA release_data['osa_release'] = osa_release # Adjust the RPC release version release_data['rpc_release'] = rpc_release # Write the file with open(release_file, 'w') as f:
def bump_minor(self): """Bump a minor version: Y from X.Y.Z """ self.version = semver.bump_minor(self.version)