Skip to content

Commit bf18026

Browse files
committed
Correct version pattern
1 parent ef345ec commit bf18026

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ fragments = [{ path = "README.rst" }]
4343
[tool.hatch.version]
4444
source = "vcs"
4545

46+
[tool.hatch.version.raw-options]
47+
# version_scheme = "no-guess-dev"
48+
version_scheme = "only-version"
49+
local_scheme = "node-and-date"
50+
# See https://setuptools-scm.readthedocs.io/en/latest/extending/#version-number-construction
51+
# for details of how the version number is constructed.
52+
# Note that the BO4E CLI which is used in the CI expects the version to be in the format how it currently is.
53+
# If you which to change the version format, you will also have to change the CLI code.
54+
4655
[tool.hatch.build.hooks.vcs]
4756
version-file = "src/_bo4e_python_version.py"
4857
template = '''

src/bo4e/version.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,43 @@
77

88
try:
99
__version__ = version("bo4e")
10+
# Please keep this name in sync with the name of the project in pyproject.toml
11+
# This name is the name of the package on pypi.org
1012
except PackageNotFoundError:
1113
__version__ = "0.0.0"
12-
# Please keep this name in sync with the name of the project in pyproject.toml
13-
# This name is the name of the package on pypi.org
14-
if re.match(r"^(\d+\.\d+\.\d+)(rc\d+)?$", __version__):
1514

16-
def _repl(match: re.Match[str]) -> str:
17-
if match.group(2) is not None:
18-
return f"v{match.group(1)}-{match.group(2)}"
19-
return f"v{match.group(1)}"
2015

21-
__gh_version__ = re.sub(r"^(\d+\.\d+\.\d+)(rc\d+)?$", _repl, __version__)
22-
else:
23-
__gh_version__ = f"v{__version__}"
16+
def _parse_version_to_gh_version(version_str: str) -> str:
17+
"""
18+
Parse a version string into a GitHub version string.
19+
E.g. '202401.0.1-rc8+dev12asdf34' becomes 'v202401.0.1-rc8'.
20+
"""
21+
_REGEX_VERSION = re.compile(
22+
r"^(?P<major>\d{6})\."
23+
r"(?P<functional>\d+)\."
24+
r"(?P<technical>\d+)"
25+
r"(?:rc(?P<candidate>\d*))?"
26+
r"(?:\+g(?P<commit_part>\w+)"
27+
r"(?:\.d(?P<dirty_workdir_date_year>\d{4})"
28+
r"(?P<dirty_workdir_date_month>\d{2})"
29+
r"(?P<dirty_workdir_date_day>\d{2}))?)?$"
30+
)
31+
match = _REGEX_VERSION.match(version_str)
32+
if match is None:
33+
raise ValueError(f"Invalid version string: {version_str}")
34+
35+
return (
36+
f"v{match.group('major')}.{match.group('functional')}.{match.group('technical')}"
37+
+ (f"-rc{match.group('candidate')}" if match.group("candidate") else "")
38+
+ (f"+g{match.group('commit_part')}" if match.group("commit_part") else "")
39+
+ (
40+
f".d{match.group('dirty_workdir_date_year')}"
41+
f"{match.group('dirty_workdir_date_month')}"
42+
f"{match.group('dirty_workdir_date_day')}"
43+
if match.group("dirty_workdir_date_year")
44+
else ""
45+
)
46+
)
47+
48+
49+
__gh_version__ = _parse_version_to_gh_version(__version__)

0 commit comments

Comments
 (0)