GH-53: Export the version of NumPy used to build the project as a constant (via setuptools/cython preprocessor injecting the value during build) #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #53
Used the approach found on this SO. It basically injects
np.__version__
during build time and defines as a constant in C/Python, available via a function imported in__init__
. Then we export__numpy_version__
in__init__.py
.Tested by installing with
pip install -e .
which usednumpy=2.1.0
. Then created a new venv, and installed this version again, but installed alsonumpy=2.0
.(above it prints
__numpy_version__
as 2.1.0 as that's the build-time version, and thennumpy 2.0.0
as that's the version my venv is using)Not sure if the most elegant way… tried different approaches, but I couldn't export/inject the
np.__version__
, as there was only aNPY_VERSION
in C NumPy, but didn't appear to match the complete NumPy version (only major?, but also couldn't export that).Added a simple unit test, that could in theory test
__numpy_version__ == np.__version__
, but I am not sure if that will be always true in CICD. Happy to change that. Also fixed a couple of typos I saw while changing the code, also happy to drop those if better.Cheers,
Bruno