From 0d615dc833e41366fa212820884f3df356682428 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Wed, 9 Jun 2021 17:32:48 -0700 Subject: [PATCH] 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. --- .github/workflows/python-package.yml | 2 +- CHANGELOG.rst | 5 ++--- setup.py | 10 ++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9c273f16..7034ab70 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -97,7 +97,7 @@ jobs: name: sdist - name: Build package in isolation run: | - pip install -v tcod-*.tar.gz + pip install tcod-*.tar.gz - name: Confirm package import run: | python -c "import tcod" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index acf81adc..190e51c3 100755 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,8 @@ v2.0.0 Unreleased ------------------ +Fixed + - Fixed version mismatch when building from sources. 12.6.0 - 2021-06-09 ------------------- @@ -19,9 +21,6 @@ Deprecated - The handling of negative indexes given to console drawing and printing functions will be changed to be used as absolute coordinates in the future. -Fixed - - Fixed version mismatch when building from sources. - 12.5.1 - 2021-05-30 ------------------- Fixed diff --git a/setup.py b/setup.py index 3d234916..9f10b161 100755 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ import os import pathlib import platform +import re import sys import warnings from subprocess import CalledProcessError, check_output @@ -37,12 +38,13 @@ def get_version() -> str: return version except CalledProcessError: try: - __version__ = "0.0.0" with open(PATH / "tcod/version.py") as version_file: - exec(version_file.read(), globals()) # Update __version__ + match = re.match(r'__version__ = "(\S+)"', version_file.read()) + assert match + return match.groups()[0] except FileNotFoundError: - warnings.warn("Unknown version: " "Not in a Git repository and not from a sdist bundle or wheel.") - return __version__ + warnings.warn("Unknown version: Not in a Git repository and not from a sdist bundle or wheel.") + return "0.0.0" is_pypy = platform.python_implementation() == "PyPy"