Skip to content

Commit f402c44

Browse files
authored
Update _version.py (#180)
1 parent 14bb200 commit f402c44

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

rendercanvas/_version.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
_version.py v1.4
2+
_version.py v1.5
33
44
Simple version string management, using a hard-coded version string
55
for simplicity and compatibility, while adding git info at runtime.
@@ -47,21 +47,18 @@ def get_extended_version() -> str:
4747
"""Get an extended version string with information from git."""
4848
release, post, labels = get_version_info_from_git()
4949

50-
# Sample first 3 parts of __version__
51-
base_release = ".".join(__version__.split(".")[:3])
52-
5350
# Start version string (__version__ string is leading)
54-
version = base_release
51+
version = base_version
5552
tag_prefix = "#"
5653

57-
if release and release != base_release:
54+
if release and release != base_version:
5855
# Can happen between bumping and tagging. And also when merging a
5956
# version bump into a working branch, because we use --first-parent.
6057
release2, _post, _labels = get_version_info_from_git(first_parent=False)
61-
if release2 != base_release:
58+
if release2 != base_version:
6259
warning(
6360
f"{project_name} version from git ({release})"
64-
f" and __version__ ({base_release}) don't match."
61+
f" and __version__ ({base_version}) don't match."
6562
)
6663
version += "+from_tag_" + release.replace(".", "_")
6764
tag_prefix = "."
@@ -121,12 +118,14 @@ def get_version_info_from_git(*, first_parent: bool = True) -> str:
121118

122119

123120
def version_to_tuple(v: str) -> tuple:
124-
v = __version__.split("+")[0] # remove hash
125-
return tuple(int(i) if i.isnumeric() else i for i in v.split("."))
126-
127-
128-
def prnt(m: str) -> None:
129-
sys.stdout.write(m + "\n")
121+
parts = []
122+
for part in v.split("."):
123+
p, _, h = part.partition("#")
124+
if p:
125+
parts.append(p)
126+
if h:
127+
parts.append("#" + h)
128+
return tuple(int(i) if i.isnumeric() else i for i in parts)
130129

131130

132131
def warning(m: str) -> None:
@@ -155,6 +154,10 @@ def warning(m: str) -> None:
155154
import sys
156155
import urllib.request
157156

157+
def prnt(m: str) -> None:
158+
sys.stdout.write(m + "\n")
159+
sys.stdout.flush()
160+
158161
_, *args = sys.argv
159162
this_file = Path(__file__)
160163

@@ -192,3 +195,4 @@ def warning(m: str) -> None:
192195
else:
193196
prnt(f"Unknown command for _version.py: {args[0]!r}")
194197
prnt("Use ``python _version.py help`` to see a list of options.")
198+
sys.exit(1)

0 commit comments

Comments
 (0)