Hook in __init__.py to let distributors patch numpy

Hi, Over at https://github.com/numpy/numpy/issues/5479 we're discussing Windows wheels. On thing that we would like to be able to ship Windows wheels, is to be able to put some custom checks into numpy when you build the wheels. Specifically, for Windows, we're building on top of ATLAS BLAS / LAPACK, and we need to check that the system on which the wheel is running, has SSE2 instructions, otherwise we know ATLAS will crash (almost everybody does have SSE2 these days). The way I propose we do that, is this patch here: https://github.com/numpy/numpy/pull/7231 diff --git a/numpy/__init__.py b/numpy/__init__.py index 0fcd509..ba3ba16 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -190,6 +190,12 @@ def pkgload(*packages, **options): test = testing.nosetester._numpy_tester().test bench = testing.nosetester._numpy_tester().bench + # Allow platform-specific build to intervene in numpy init + try: + from . import _distributor_init + except ImportError: + pass + from . import core from .core import * from . import compat So, numpy __init__.py looks for a module `_distributor_init`, in which the distributor might have put custom code to do any checks and initialization needed for the particular platform. We don't by default ship a `_distributor_init.py` but leave it up to packagers to generate this when building binaries. Does that sound like a sensible approach to y'all? Cheers, Matthew

+1. This seems nicer than patching __init__.py itself, in that it is much more transparent. Good idea. Michael On Thu, Feb 11, 2016 at 7:19 PM Matthew Brett <matthew.brett@gmail.com> wrote:
Hi,
Over at https://github.com/numpy/numpy/issues/5479 we're discussing Windows wheels.
On thing that we would like to be able to ship Windows wheels, is to be able to put some custom checks into numpy when you build the wheels.
Specifically, for Windows, we're building on top of ATLAS BLAS / LAPACK, and we need to check that the system on which the wheel is running, has SSE2 instructions, otherwise we know ATLAS will crash (almost everybody does have SSE2 these days).
The way I propose we do that, is this patch here:
https://github.com/numpy/numpy/pull/7231
diff --git a/numpy/__init__.py b/numpy/__init__.py index 0fcd509..ba3ba16 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -190,6 +190,12 @@ def pkgload(*packages, **options): test = testing.nosetester._numpy_tester().test bench = testing.nosetester._numpy_tester().bench
+ # Allow platform-specific build to intervene in numpy init + try: + from . import _distributor_init + except ImportError: + pass + from . import core from .core import * from . import compat
So, numpy __init__.py looks for a module `_distributor_init`, in which the distributor might have put custom code to do any checks and initialization needed for the particular platform. We don't by default ship a `_distributor_init.py` but leave it up to packagers to generate this when building binaries.
Does that sound like a sensible approach to y'all?
Cheers,
Matthew _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion

I would add a numpy/_distributor_init.py module and unconditionally import it in the __init__.py. It's contents in our upstream sources would just be a docstring: """Distributors! Put your initialization code here! """ One important technical benefit is that the unconditional import won't hide ImportErrors in the distributor's code. On Fri, Feb 12, 2016 at 1:19 AM, Matthew Brett <matthew.brett@gmail.com> wrote:
Hi,
Over at https://github.com/numpy/numpy/issues/5479 we're discussing Windows wheels.
On thing that we would like to be able to ship Windows wheels, is to be able to put some custom checks into numpy when you build the wheels.
Specifically, for Windows, we're building on top of ATLAS BLAS / LAPACK, and we need to check that the system on which the wheel is running, has SSE2 instructions, otherwise we know ATLAS will crash (almost everybody does have SSE2 these days).
The way I propose we do that, is this patch here:
https://github.com/numpy/numpy/pull/7231
diff --git a/numpy/__init__.py b/numpy/__init__.py index 0fcd509..ba3ba16 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -190,6 +190,12 @@ def pkgload(*packages, **options): test = testing.nosetester._numpy_tester().test bench = testing.nosetester._numpy_tester().bench
+ # Allow platform-specific build to intervene in numpy init + try: + from . import _distributor_init + except ImportError: + pass + from . import core from .core import * from . import compat
So, numpy __init__.py looks for a module `_distributor_init`, in which the distributor might have put custom code to do any checks and initialization needed for the particular platform. We don't by default ship a `_distributor_init.py` but leave it up to packagers to generate this when building binaries.
Does that sound like a sensible approach to y'all?
Cheers,
Matthew _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
-- Robert Kern
participants (3)
-
Matthew Brett
-
Michael Sarahan
-
Robert Kern