Discussion:
[Numpy-discussion] Hook in __init__.py to let distributors patch numpy
Matthew Brett
2016-02-12 01:19:09 UTC
Permalink
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
Michael Sarahan
2016-02-12 01:24:02 UTC
Permalink
+1. This seems nicer than patching __init__.py itself, in that it is much
more transparent.

Good idea.
Michael
Post by Matthew Brett
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).
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
test = testing.nosetester._numpy_tester().test
bench = testing.nosetester._numpy_tester().bench
+ # Allow platform-specific build to intervene in numpy init
+ from . import _distributor_init
+ 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
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Robert Kern
2016-02-12 09:37:52 UTC
Permalink
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.
Post by Matthew Brett
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).
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
test = testing.nosetester._numpy_tester().test
bench = testing.nosetester._numpy_tester().bench
+ # Allow platform-specific build to intervene in numpy init
+ from . import _distributor_init
+ 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
https://mail.scipy.org/mailman/listinfo/numpy-discussion
--
Robert Kern
Loading...