Skip to content

Commit bb8bdcd

Browse files
committed
fix issue in version that was leading to automation errors
1 parent 684df0f commit bb8bdcd

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

‎src/giant_python/__init__.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@
4242
"StandardSourceExtractor",
4343
"TrialTable",
4444
"TrialTableBuilder",
45-
"__version__ = "0.1.6"
4645
]

‎tests/test_package_metadata.py‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,51 @@
55
from pathlib import Path
66

77

8-
PACKAGE_INIT = Path(__file__).resolve().parents[1] / (
9-
"src/giant_python/__init__.py"
8+
PACKAGE_INIT = (
9+
Path(__file__).resolve().parents[1] / "src" / "giant_python" / "__init__.py"
1010
)
1111

1212

1313
class PackageMetadataTest(unittest.TestCase):
1414
"""Tests for package metadata declarations."""
1515

16-
def test_init_module_is_valid_and_exports_version(self):
17-
"""The package __init__ module should parse and export __version__."""
18-
module = ast.parse(PACKAGE_INIT.read_text(encoding="utf-8"))
16+
def test_init_module_is_valid_and_has_single_version_line(self):
17+
"""Only one ``__version__`` line may exist so CI sed bumps stay safe.
1918
20-
all_assignment = next(
19+
The shared AIND ``release-bump-version`` workflow rewrites every line
20+
that contains ``__version__`` with::
21+
22+
sed 's|__version__.*|__version__ = "X.Y.Z"|'
23+
24+
Listing ``"__version__"`` in ``__all__`` therefore produces invalid
25+
Python on the next bump. Keep a single assignment line instead.
26+
"""
27+
source = PACKAGE_INIT.read_text(encoding="utf-8")
28+
module = ast.parse(source)
29+
30+
version_lines = [
31+
line for line in source.splitlines() if "__version__" in line
32+
]
33+
self.assertEqual(len(version_lines), 1)
34+
self.assertRegex(
35+
version_lines[0].strip(),
36+
r'^__version__ = "[0-9]+\.[0-9]+\.[0-9]+"$',
37+
)
38+
39+
version_assignment = next(
2140
node
2241
for node in module.body
2342
if isinstance(node, ast.Assign)
2443
and any(
25-
isinstance(target, ast.Name) and target.id == "__all__"
44+
isinstance(target, ast.Name) and target.id == "__version__"
2645
for target in node.targets
2746
)
2847
)
29-
self.assertIsInstance(all_assignment.value, (ast.List, ast.Tuple))
30-
exported_names = [
31-
elt.value
32-
for elt in all_assignment.value.elts
33-
if isinstance(elt, ast.Constant) and isinstance(elt.value, str)
34-
]
35-
36-
self.assertIn("__version__", exported_names)
48+
self.assertIsInstance(version_assignment.value, ast.Constant)
49+
self.assertIsInstance(version_assignment.value.value, str)
50+
self.assertRegex(
51+
version_assignment.value.value, r"^[0-9]+\.[0-9]+\.[0-9]+$"
52+
)
3753

3854

3955
if __name__ == "__main__":

0 commit comments

Comments
 (0)