Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_bump(self, what):
if self.problem:
setupmeta.abort(self.problem)
gv = self.scm.get_version()
return self.strategy.bumped(what, gv)
def verify_remote_tags(self):
"""Verify that remote tags are identical to local tags"""
local_tags = self.scm.local_tags()
remote_tags = self.scm.remote_tags()
local_only = local_tags.difference(remote_tags)
remote_only = remote_tags.difference(local_tags)
if remote_only:
message = "Can't bump: not all remote tags are present locally!\n"
if local_only:
message += "Tags only seen locally: %s\n" % ", ".join(local_only)
if remote_only:
message += "Tags only on remote: %s\n" % ", ".join(remote_only)
setupmeta.abort(message)
def bumped(self, what, current_version):
"""
:param str what: Which component to bump
:param Version current_version: Current version
:return str: Represented next version, with 'what' bumped
"""
if not isinstance(self.main_bits, list):
setupmeta.abort("Main format is not a list: %s" % setupmeta.stringify(self.main_bits))
if what not in self.bumpable:
msg = "Can't bump '%s', it's out of scope" % what
msg += " of main format '%s'" % self.main
msg += " acceptable values: %s" % ", ".join(self.bumpable)
setupmeta.abort(msg)
major, minor, rev = current_version.major, current_version.minor, current_version.patch
if what == "major":
major, minor, rev = (major + 1, 0, 0)
elif what == "minor":
major, minor, rev = (major, minor + 1, 0)
elif what == "patch":
major, minor, rev = (major, minor, rev + 1)
def apply_tag(self, commit, push, next_version, branch):
self.get_output("fetch", "--all")
output = self.get_output("status", "--porcelain", "--branch")
for line in output.splitlines():
m = RE_BRANCH_STATUS.match(line)
if m and m.group(1) == branch:
state = m.group(6)
if state and ("behind" in state or "gone" in state):
# Example: Local branch 'master' is out of date (behind 1), can't bump
setupmeta.abort("Local branch '%s' is out of date (%s), can't bump" % (branch, state))
bump_msg = "Version %s" % next_version
tag = "v%s" % next_version
self.run(commit, "tag", "-a", tag, "-m", bump_msg)
if push:
if self.has_origin():
self.run(commit, "push", "--tags", "origin")
else:
print("Not running 'git push --tags origin' as you don't have an origin")
def bumped(self, what, current_version):
"""
:param str what: Which component to bump
:param Version current_version: Current version
:return str: Represented next version, with 'what' bumped
"""
if not isinstance(self.main_bits, list):
setupmeta.abort("Main format is not a list: %s" % setupmeta.stringify(self.main_bits))
if what not in self.bumpable:
msg = "Can't bump '%s', it's out of scope" % what
msg += " of main format '%s'" % self.main
msg += " acceptable values: %s" % ", ".join(self.bumpable)
setupmeta.abort(msg)
major, minor, rev = current_version.major, current_version.minor, current_version.patch
if what == "major":
major, minor, rev = (major + 1, 0, 0)
elif what == "minor":
major, minor, rev = (major, minor + 1, 0)
elif what == "patch":
major, minor, rev = (major, minor, rev + 1)
next_version = Version(main="%s.%s.%s" % (major, minor, rev))
return self.rendered(next_version, extra=False)
def bump(self, what, commit=False, push=False, simulate_branch=None):
if self.problem:
setupmeta.abort(self.problem)
branch = simulate_branch or self.scm.get_branch()
if branch not in self.strategy.branches:
setupmeta.abort("Can't bump branch '%s', need one of %s" % (branch, self.strategy.branches))
gv = self.scm.get_version()
if gv and gv.dirty:
if commit:
setupmeta.abort("You have pending changes, can't bump")
print("Note: you have pending changes, commit (or stash) them before using --commit")
self.verify_remote_tags()
next_version = self.strategy.bumped(what, gv)
if not commit:
print("Not committing bump, use --commit to commit")
if not push:
print("Not pushing bump, use --push to push")
vdefs = self.meta.definitions.get("version")
if vdefs:
self.update_sources(next_version, commit, push, vdefs)
def bump(self, what, commit=False, push=False, simulate_branch=None):
if self.problem:
setupmeta.abort(self.problem)
branch = simulate_branch or self.scm.get_branch()
if branch not in self.strategy.branches:
setupmeta.abort("Can't bump branch '%s', need one of %s" % (branch, self.strategy.branches))
gv = self.scm.get_version()
if gv and gv.dirty:
if commit:
setupmeta.abort("You have pending changes, can't bump")
print("Note: you have pending changes, commit (or stash) them before using --commit")
self.verify_remote_tags()
next_version = self.strategy.bumped(what, gv)
if not commit:
print("Not committing bump, use --commit to commit")
if not push: