[pypy-commit] pypy default: Add a module 'numpy' which raises an ImportError giving a detailed

arigo noreply at buildbot.pypy.org
Wed Feb 8 13:51:23 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r52227:65001a8720b8
Date: 2012-02-08 13:50 +0100
http://bitbucket.org/pypy/pypy/changeset/65001a8720b8/

Log:	Add a module 'numpy' which raises an ImportError giving a detailed
	explanation. Tweak 'numpypy' to replace 'numpy' when imported.

diff --git a/lib_pypy/numpy.py b/lib_pypy/numpy.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpy.py
@@ -0,0 +1,5 @@
+raise ImportError(
+    "The 'numpy' module of PyPy is in-development and not complete. "
+    "To try it out anyway, you can either import from 'numpypy', "
+    "or just write 'import numpypy' first in your program and then "
+    "import from 'numpy' as usual.")
diff --git a/lib_pypy/numpypy/__init__.py b/lib_pypy/numpypy/__init__.py
--- a/lib_pypy/numpypy/__init__.py
+++ b/lib_pypy/numpypy/__init__.py
@@ -1,2 +1,5 @@
 from _numpypy import *
 from .core import *
+
+import sys
+sys.modules.setdefault('numpy', sys.modules['numpypy'])
diff --git a/pypy/module/test_lib_pypy/numpypy/test_numpy.py b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
@@ -0,0 +1,13 @@
+from pypy.conftest import gettestobjspace
+
+class AppTestNumpy:
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['micronumpy'])
+
+    def test_imports(self):
+        try:
+            import numpy   # fails if 'numpypy' was not imported so far
+        except ImportError:
+            pass
+        import numpypy
+        import numpy     # works after 'numpypy' has been imported


More information about the pypy-commit mailing list