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
Use importlib to load numba extensions #5209
Conversation
@svrakitin thanks for submitting this and congrats on submitting your first PR to Numba. I have queued it for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT just two small remarks.
This one adds |
numba/core/entrypoints.py
Outdated
try: | ||
from importlib import metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this fails? I'm wondering if there ought to be an explicit Python>=3.8 branch which just imports it and then another which tries and fails gracefully if the package is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will only fail on Python < 3.8 if importlib_metadata is missing (it is listed as requirement).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to assume nothing about how Numba was built, it's entirely possible someone just grabbed the source and some limited set of bootstrap packages available for their unusual architecture and built it (this actually happens in practice, we see these people on the issue tracker when strange things happen!). As a result, we tend to err on the side of trying to be as helpful as possible and catch things like this and say something about it being needed.
Further, this will need adding to the dependencies section in the docs: https://github.com/numba/numba/blob/13ece9b97e6f01f750e870347f231282325f60c3/docs/source/user/installing.rst#dependency-list
Note to reviewers: Someone needs to go and manually test this for Python 3.7 and 3.8 against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the new dependency should still be added to http://numba.pydata.org/numba-doc/latest/user/installing.html#dependency-list and also potentially setup.py
. Looks good beyond that.
BTW: how hard is this dependency? |
@esc It is non-optional run time dependency. |
In that case, I believe it should be added to |
Actually |
@svrakitin thanks for submitting the fixes, I have now marked it as waiting for reviewer input. @stuartarchibald @sklam what say you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. There's a couple of tiny things to resolve (we should use conda packages ahead of pip!).
Otherwise, this PR seems technically fine and gets approval from me. More generally the core developers will need to agree on accepting importlib_metadata
as a hard dependency but I do not anticipate this being a problem.
@esc any chance you could please test run this with numba-scipy
to make sure it works ok in practice, thanks.
@@ -32,6 +32,7 @@ call activate %CONDA_ENV% | |||
if %PYTHON% LSS 3.4 (%CONDA_INSTALL% enum34) | |||
if %PYTHON% LSS 3.4 (%PIP_INSTALL% singledispatch) | |||
if %PYTHON% LSS 3.3 (%CONDA_INSTALL% -c numba funcsigs) | |||
if %PYTHON% LSS 3.8 (%PIP_INSTALL% importlib-metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps get this from the Anaconda distro?!
@@ -80,6 +80,8 @@ $CONDA_INSTALL -c numba llvmlite | |||
# Install enum34 and singledispatch for Python < 3.4 | |||
if [ $PYTHON \< "3.4" ]; then $CONDA_INSTALL enum34; fi | |||
if [ $PYTHON \< "3.4" ]; then $PIP_INSTALL singledispatch; fi | |||
# Install importlib-metadata for Python < 3.8 | |||
if [ $PYTHON \< "3.8" ]; then $PIP_INSTALL importlib-metadata; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps get this from the Anaconda distro?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes. Code changes approved. This now needs manual and build farm testing.
@@ -98,6 +98,8 @@ fi | |||
# Install latest llvmlite build | |||
$CONDA_INSTALL -c numba/label/dev llvmlite | |||
|
|||
# Install importlib-metadata for Python < 3.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Install importlib-metadata for Python < 3.8 | |
# Install importlib-metadata for Python < 3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating and testing this @gmarkall . Few minor things to look at else I think this is ready for testing on the farm. Thanks again!
# On channel https://anaconda.org/numba/ | ||
- importlib_metadata # [py<39] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# On channel https://anaconda.org/numba/ | |
- importlib_metadata # [py<39] | |
- importlib_metadata # [py<39] | |
# On channel https://anaconda.org/numba/ |
looks like this comment is now on the incorrect line.
# On channel https://anaconda.org/numba/ | ||
- llvmlite >=0.39.0dev0,<0.39 | ||
- importlib_metadata # [py<39] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# On channel https://anaconda.org/numba/ | |
- llvmlite >=0.39.0dev0,<0.39 | |
- importlib_metadata # [py<39] | |
- importlib_metadata # [py<39] | |
# On channel https://anaconda.org/numba/ | |
- llvmlite >=0.39.0dev0,<0.39 |
self.assertEqual(counters['init'], 1) | ||
# was our init function called? | ||
mod.init_func.assert_called_once() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a similar change can also be made to test_entrypoint_tolerance
as part of this clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar change made - note this also involves configuring the mock with a side effect for init_func()
.
This also removes the Python 2-specific workaround :-)
@stuartarchibald Many thanks for the reviews - the most recent comments should now be addressed. |
Thanks @gmarkall, the updates look good. If you are happy to:
Then I'm happy to approve this patch. Many thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved re 724990f which is authored by @stuartarchibald.
gpuci run tests. |
Thanks @gmarkall |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the effort on this! Looks good.
Buildfarm ID: |
Passed. |
@svrakitin Many thanks for your efforts here! 🎉 |
@gmarkall Hah, thanks for getting this to the end. :) |
Closes #4927