Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def returns_lexica_for_reuse(self):
actions = Lexicon(
changelog=Changelog.NEEDS_RELEASE,
version=VersionFile.NEEDS_BUMP,
tag=Tag.NEEDS_CUTTING,
)
found_actions, found_state = _mock_status(self)
assert found_actions == actions
# Spot check state, don't need to check whole thing...
assert found_state.branch == self._branch
assert found_state.latest_version == Version("1.1.1")
assert found_state.tags == [Version(x) for x in self._tags]
def next_patch_of_bugfix_release(self):
versions = _latest_and_next_version(
Lexicon(
{
"release_type": Release.BUGFIX,
"latest_line_release": Version("1.2.2"),
"latest_overall_release": Version("1.4.1"), # realism!
}
)
)
assert versions == (Version("1.2.2"), Version("1.2.3"))
def next_patch_of_bugfix_release(self):
versions = _latest_and_next_version(
Lexicon(
{
"release_type": Release.BUGFIX,
"latest_line_release": Version("1.2.2"),
"latest_overall_release": Version("1.4.1"), # realism!
}
)
)
assert versions == (Version("1.2.2"), Version("1.2.3"))
def _get_tags(c):
"""
Return sorted list of release-style tags as semver objects.
"""
tags_ = []
for tagstr in c.run("git tag", hide=True).stdout.strip().split("\n"):
try:
tags_.append(Version(tagstr))
# Ignore anything non-semver; most of the time they'll be non-release
# tags, and even if they are, we can't reason about anything
# non-semver anyways.
# TODO: perhaps log these to DEBUG
except ValueError:
pass
# Version objects sort semantically
return sorted(tags_)
def _versions_from_changelog(changelog):
"""
Return all released versions from given ``changelog``, sorted.
:param dict changelog:
A changelog dict as returned by ``releases.util.parse_changelog``.
:returns: A sorted list of `semantic_version.Version` objects.
"""
versions = [Version(x) for x in changelog if BUGFIX_RELEASE_RE.match(x)]
return sorted(versions)
# current line
line_release, issues = _release_and_issues(changelog, branch, release_type)
# Also get latest overall release, sometimes that matters (usually only
# when latest *appropriate* release doesn't exist yet)
overall_release = _versions_from_changelog(changelog)[-1]
# Obtain the project's main package & its version data
current_version = load_version(c)
# Grab all git tags
tags = _get_tags(c)
state = Lexicon(
{
"branch": branch,
"release_type": release_type,
"changelog": changelog,
"latest_line_release": Version(line_release)
if line_release
else None,
"latest_overall_release": overall_release, # already a Version
"unreleased_issues": issues,
"current_version": Version(current_version),
"tags": tags,
}
)
# Version number determinations:
# - latest actually-released version
# - the next version after that for current branch
# - which of the two is the actual version we're looking to converge on,
# depends on current changelog state.
latest_version, next_version = _latest_and_next_version(state)
state.latest_version = latest_version
state.next_version = next_version