From 48134b97218cea221168f355b61d28b4063dc3fc Mon Sep 17 00:00:00 2001 From: Thomas Willson Date: Wed, 17 Dec 2025 09:33:46 -0800 Subject: [PATCH] Handle patch release versions. --- .flake8 | 2 +- .gitignore | 5 ++++- staflversion/cli.py | 3 +-- staflversion/git.py | 1 - staflversion/version.py | 12 ++++++------ tests/test_git.py | 3 ++- tests/test_version.py | 8 ++++++++ 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.flake8 b/.flake8 index 5cf4b0b..1753af7 100644 --- a/.flake8 +++ b/.flake8 @@ -5,7 +5,7 @@ exclude= env, build, dist -max-line-length = 88 +max-line-length = 120 # E203: whitespace before ":". Sometimes violated by black. # E402: Module level import not at top of file. Violated by lazy imports. # F401: Module imported but unused. diff --git a/.gitignore b/.gitignore index 263d857..79286cd 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,7 @@ dmypy.json # example output example/*.csv -settings.json \ No newline at end of file +settings.json + +# macOS files +.DS_Store \ No newline at end of file diff --git a/staflversion/cli.py b/staflversion/cli.py index aae69d1..a9246fb 100644 --- a/staflversion/cli.py +++ b/staflversion/cli.py @@ -1,5 +1,4 @@ -"""CLI interface for staflversion project. -""" +"""CLI interface for staflversion project.""" import argparse diff --git a/staflversion/git.py b/staflversion/git.py index 6c17c08..e8492ab 100644 --- a/staflversion/git.py +++ b/staflversion/git.py @@ -5,7 +5,6 @@ here you put your main classes and objects. """ - import subprocess from typing import List, Optional diff --git a/staflversion/version.py b/staflversion/version.py index 4da0f55..9c777dd 100644 --- a/staflversion/version.py +++ b/staflversion/version.py @@ -9,7 +9,7 @@ @total_ordering class StaflVersion: VERSION_REGEX = re.compile( - r"^(?P\d+)\.(?P\d+)\.(?P\d+)\+(?P\d+)$" + r"^(?P\d+)\.(?P\d+)\.(?P\d+)\+(?P\d+)(-(?P.+))?$" ) def __init__(self, major: int, minor: int, patch: int, build: int): @@ -85,14 +85,16 @@ class StaflVersioner: _INCREMENT_MAJOR = "+semver:major" _INCREMENT_MINOR = "+semver:minor" _INCREMENT_PATCH = "+semver:patch" - _SET_VERSION = re.compile(r"\+semver-set:" + StaflVersion.VERSION_REGEX.pattern[1:-1]) + _SET_VERSION = re.compile( + r"\+semver-set:" + StaflVersion.VERSION_REGEX.pattern[1:-1] + ) def __init__(self, git: GitWrapper): self._git = git def determine_version(self) -> StaflVersion: tags = self._git.get_tags() - + if tags: new_commit_messages = self._git.get_commit_messages_since_tag() else: @@ -109,9 +111,7 @@ def determine_version(self) -> StaflVersion: increment_patch = any([self._INCREMENT_PATCH in m for m in new_commit_messages]) versions = [ - StaflVersion.parse(t) - for t in tags - if StaflVersion.try_parse(t) is not None + StaflVersion.parse(t) for t in tags if StaflVersion.try_parse(t) is not None ] versions.sort(reverse=True) last_version = versions[0] if versions else StaflVersion(0, 0, 0, 0) diff --git a/tests/test_git.py b/tests/test_git.py index d292150..9730332 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -15,7 +15,8 @@ def tempdir(): @pytest.fixture def sample_repo(tempdir: str, monkeypatch: MonkeyPatch): - # tempdir above must come before monkeypatch so that the directory is changed back before the directory is cleanup up + # tempdir above must come before monkeypatch so that the directory is + # changed back before the directory is cleaned up monkeypatch.chdir(tempdir) system( "git init &&\ diff --git a/tests/test_version.py b/tests/test_version.py index 2b69457..f79126a 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -132,3 +132,11 @@ def test_version_determine_set_version(): ) versioner = StaflVersioner(git) assert versioner.determine_version() == StaflVersion(1, 2, 3, 4) + + +def test_version_patch_release(): + git = MockGitWrapper( + ["Fix critical bug +semver:patch"], ["1.2.3+4-dev/patch", "1.2.2+0"] + ) + versioner = StaflVersioner(git) + assert versioner.determine_version() == StaflVersion(1, 2, 4, 0)