Skip to content

Commit c3da618

Browse files
authored
Merge pull request #301 from BCG-Gamma/dev/1.2.4
BUILD: release pytools 1.2.4
2 parents e62f549 + 499a3a6 commit c3da618

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

RELEASE_NOTES.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Release Notes
44
*pytools* 1.2
55
-------------
66

7+
1.2.4
8+
~~~~~
9+
10+
This is a maintenance release to catch up with *pytools* 1.1.8.
11+
12+
713
1.2.3
814
~~~~~
915

@@ -47,12 +53,20 @@ This is a maintenance release to catch up with *pytools* 1.1.4.
4753
*pytools* 1.1
4854
-------------
4955

56+
1.1.8
57+
~~~~~
58+
59+
- BUILD: the ``make_base.py`` build script no longer imports the actual module to obtain
60+
the current package version, similarly as introduced for ``make.py`` in
61+
*pytools* 1.1.7
62+
63+
5064
1.1.7
5165
~~~~~
5266

53-
- BUILD: update the ``make.py`` build script to removes its reliance on importing the
67+
- BUILD: update the ``make.py`` build script to remove its reliance on importing the
5468
actual module just to obtain the build version; instead, ``make.py`` now scans the
55-
top-level ``__init__.py`` file for a ``__version__`` declaration.
69+
top-level ``__init__.py`` file for a ``__version__`` declaration
5670

5771

5872
1.1.6

sphinx/base/make_base.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"""
33
Sphinx documentation build script
44
"""
5-
import importlib
6-
import importlib.util
75
import json
86
import os
97
import re
@@ -28,7 +26,7 @@
2826
DIR_MAKE_BASE = os.path.dirname(os.path.realpath(__file__))
2927
DIR_REPO_ROOT = os.path.realpath(os.path.join(os.getcwd(), os.pardir))
3028
DIR_REPO_PARENT = os.path.realpath(os.path.join(DIR_REPO_ROOT, os.pardir))
31-
FACET_PROJECT = os.path.split(os.path.realpath(DIR_REPO_ROOT))[1]
29+
PROJECT_NAME = os.path.split(os.path.realpath(DIR_REPO_ROOT))[1]
3230
DIR_PACKAGE_SRC = os.path.join(DIR_REPO_ROOT, "src")
3331
DIR_DOCS = os.path.join(DIR_REPO_ROOT, "docs")
3432
DIR_SPHINX_SOURCE = os.path.join(cwd, "source")
@@ -51,6 +49,9 @@
5149
# noinspection SpellCheckingInspection
5250
ENV_PYTHON_PATH = "PYTHONPATH"
5351

52+
# regex pattern to match the version declaration in a top-level __init__.py
53+
RE_VERSION_DECLARATION = re.compile(r"\b__version__\s*=\s*(?:\"([^\"]*)\"|'([^']*)')")
54+
5455
T = TypeVar("T")
5556

5657

@@ -529,25 +530,34 @@ def get_package_version() -> pkg_version.Version:
529530
"""
530531
Retrieve the package version for the project from __init__ or _version
531532
"""
532-
project_src = os.path.abspath(os.path.join(DIR_REPO_ROOT, "src"))
533+
init_path = os.path.abspath(
534+
os.path.join(DIR_REPO_ROOT, "src", PROJECT_NAME, "__init__.py")
535+
)
536+
537+
print(f"Retrieving package version from {init_path}")
538+
539+
with open(init_path, "rt") as init_file:
540+
init_lines = init_file.readlines()
533541

534-
if FACET_PROJECT in ("sklearndf", "flow"):
535-
# for sklearndf and flow __init__ can't be trivially imported due to import
536-
# dependencies. Load the version as defined in FACET_PROJECT._version module
537-
spec = importlib.util.spec_from_file_location(
538-
"_version", os.path.join(project_src, FACET_PROJECT, "_version.py")
542+
matches = {
543+
match[1] or match[2]
544+
for match in (RE_VERSION_DECLARATION.match(line) for line in init_lines)
545+
if match
546+
}
547+
548+
if len(matches) == 0:
549+
raise RuntimeError(f"No valid __version__ declaration found in {init_path}")
550+
551+
elif len(matches) > 1:
552+
raise RuntimeError(
553+
f"Multiple conflicting __version__ declarations found in {init_path}: "
554+
f"{matches}"
539555
)
556+
540557
else:
541-
# pytools/facet: retrieve version from __init__.py
542-
spec = importlib.util.spec_from_file_location(
543-
"_version", os.path.join(project_src, FACET_PROJECT, "__init__.py")
544-
)
558+
package_version = next(iter(matches))
545559

546-
version_module = importlib.util.module_from_spec(spec)
547-
# noinspection PyUnresolvedReferences
548-
spec.loader.exec_module(version_module)
549-
# noinspection PyUnresolvedReferences
550-
return pkg_version.parse(version_module.__version__)
560+
return pkg_version.parse(package_version)
551561

552562

553563
def is_azure_build() -> bool:

src/pytools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
A collection of Python extensions and tools used in BCG GAMMA's open-source libraries.
33
"""
4-
__version__ = "1.2.3"
4+
__version__ = "1.2.4"

0 commit comments

Comments
 (0)