Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

kinow
Copy link
Contributor

@kinow kinow commented Aug 25, 2024

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 used numpy=2.1.0. Then created a new venv, and installed this version again, but installed also numpy=2.0.

(venv2) kinow@ranma:~/Development/python/workspace/crick$ pip install numpy==2.0
Collecting numpy==2.0
  Using cached numpy-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
Using cached numpy-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB)
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 2.1.0
    Uninstalling numpy-2.1.0:
      Successfully uninstalled numpy-2.1.0
Successfully installed numpy-2.0.0
(venv2) kinow@ranma:~/Development/python/workspace/crick$ python -c 'from crick import __numpy_version__; print(__numpy_version__)'
b'2.1.0'
(venv2) kinow@ranma:~/Development/python/workspace/crick$ pip list | grep numpy
numpy   2.0.0

(above it prints __numpy_version__ as 2.1.0 as that's the build-time version, and then numpy 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 a NPY_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

Copy link
Collaborator

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me

@phofl
Copy link
Collaborator

phofl commented Aug 26, 2024

looks like pre-commit isn't happy

@kinow
Copy link
Contributor Author

kinow commented Aug 26, 2024

looks like pre-commit isn't happy

Sorry, hadn't seen that. Will fix it.

@kinow kinow force-pushed the gh-53-export-numpy-version branch from 375643c to 057caee Compare August 26, 2024 12:00
@kinow
Copy link
Contributor Author

kinow commented Aug 26, 2024

Applied linter proposed fixes manually, I think the workflow is waiting approval now (first time contributor here). Thanks!

@phofl
Copy link
Collaborator

phofl commented Aug 26, 2024

seems still to be failing, you should be able to copy from the log of the pre commit job

… constant (via setuptools/cython preprocessor injecting the value during build)
@kinow kinow force-pushed the gh-53-export-numpy-version branch from 057caee to 0264a61 Compare August 26, 2024 19:27
@kinow
Copy link
Contributor Author

kinow commented Aug 26, 2024

seems still to be failing, you should be able to copy from the log of the pre commit job

I should have done that the first time. Copy-pasted, removed + signs, I hope it's right this time 🤞

@phofl phofl merged commit 70bc5ad into dask:main Aug 26, 2024
20 checks passed
@phofl
Copy link
Collaborator

phofl commented Aug 26, 2024

thx

@kinow kinow deleted the gh-53-export-numpy-version branch August 26, 2024 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document the version of NumPy used to build the packages
2 participants