Skip to content

Commit 0d615dc

Browse files
committed
Fix version detection.
The previous code was adding `__version__` to the globals which was then ignored as there was a local version of the same name. The new code is a lot more strict and no longer uses exec. The verbose pip install wasn't needed.
1 parent 19e08a6 commit 0d615dc

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
name: sdist
9898
- name: Build package in isolation
9999
run: |
100-
pip install -v tcod-*.tar.gz
100+
pip install tcod-*.tar.gz
101101
- name: Confirm package import
102102
run: |
103103
python -c "import tcod"

CHANGELOG.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Fixed
12+
- Fixed version mismatch when building from sources.
1113

1214
12.6.0 - 2021-06-09
1315
-------------------
@@ -19,9 +21,6 @@ Deprecated
1921
- The handling of negative indexes given to console drawing and printing
2022
functions will be changed to be used as absolute coordinates in the future.
2123

22-
Fixed
23-
- Fixed version mismatch when building from sources.
24-
2524
12.5.1 - 2021-05-30
2625
-------------------
2726
Fixed

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import pathlib
55
import platform
6+
import re
67
import sys
78
import warnings
89
from subprocess import CalledProcessError, check_output
@@ -37,12 +38,13 @@ def get_version() -> str:
3738
return version
3839
except CalledProcessError:
3940
try:
40-
__version__ = "0.0.0"
4141
with open(PATH / "tcod/version.py") as version_file:
42-
exec(version_file.read(), globals()) # Update __version__
42+
match = re.match(r'__version__ = "(\S+)"', version_file.read())
43+
assert match
44+
return match.groups()[0]
4345
except FileNotFoundError:
44-
warnings.warn("Unknown version: " "Not in a Git repository and not from a sdist bundle or wheel.")
45-
return __version__
46+
warnings.warn("Unknown version: Not in a Git repository and not from a sdist bundle or wheel.")
47+
return "0.0.0"
4648

4749

4850
is_pypy = platform.python_implementation() == "PyPy"

0 commit comments

Comments
 (0)