Skip to content

Commit fde4c6d

Browse files
committed
fix(build): read version statically from brainpy._version
PR #865 moved __version__ into brainpy/_version.py and made __init__ re-export it. That broke static version resolution for consumers still pointing at brainpy.__init__: - pyproject.toml used `attr = "brainpy.__version__"`. setuptools reads attr via AST only when it is a literal assignment; after the move __init__ exposes the name through an ImportFrom, so setuptools falls back to importing the whole brainpy package. In Publish.yml's isolated `python -m build` env (no jax / brainstate) that import fails. Point the attr at brainpy._version.__version__, which resolves statically without importing the package. - docs/conf.py imported the full brainpy package solely to read brainpy.__version__. Read it directly from brainpy._version instead. brainpy/__init__.py keeps re-exporting __version__/__version_info__, so bp.__version__ still works for users.
1 parent ca1d233 commit fde4c6d

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656

5757
fix_ipython2_lexer_in_notebooks(os.path.dirname(os.path.abspath(__file__)))
5858

59-
import brainpy
60-
61-
release = brainpy.__version__
59+
from brainpy._version import __version__ as release
6260

6361
# -- General configuration ---------------------------------------------------
6462

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ exclude = [
8282
]
8383

8484
[tool.setuptools.dynamic]
85-
version = { attr = "brainpy.__version__" }
85+
# Read the version statically from the tiny ``brainpy/_version.py`` module. Pointing at
86+
# ``brainpy.__version__`` would force setuptools to import the whole package at build time
87+
# (``__init__`` only re-exports the name), which fails in the isolated ``python -m build``
88+
# environment where BrainPy's runtime deps are absent.
89+
version = { attr = "brainpy._version.__version__" }
8690

8791

8892
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)