summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Brett <matthew.brett@gmail.com>2015-12-10 16:24:08 -0800
committerMatthew Brett <matthew.brett@gmail.com>2015-12-10 16:24:08 -0800
commitc2b6ab9924271b96d3c783f7818723a1bb8f511a (patch)
treef88b40237cb6954960f906aa9358c74334839c21
parentedb902cdc6573553afcf11047ecdfb447e444322 (diff)
parentb064e4b4cb3f8d571605ee8a7f53c9ce2d5df879 (diff)
downloadnumpy-maintenance/1.9.x.tar.gz
Merge pull request #6350 from matthew-brett/prepare-1.9.4maintenance/1.9.x
MRG: preparing for potential 1.9.4 release Fix f2py shebang line error for wheel installs.
-rw-r--r--.travis.yml4
-rw-r--r--numpy/f2py/__main__.py23
-rw-r--r--numpy/f2py/setup.py44
-rw-r--r--numpy/tests/test_scripts.py65
-rwxr-xr-xtools/travis-test.sh13
5 files changed, 120 insertions, 29 deletions
diff --git a/.travis.yml b/.travis.yml
index 12a443d41..eba6890df 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,6 +31,10 @@ before_install:
- ulimit -a
- mkdir builds
- pushd builds
+ # Build into own virtualenv
+ # We therefore control our own environment, avoid travis' numpy
+ - virtualenv --python=python venv
+ - source venv/bin/activate
- pip install nose
# pip install coverage
- python -V
diff --git a/numpy/f2py/__main__.py b/numpy/f2py/__main__.py
new file mode 100644
index 000000000..11dbf5f52
--- /dev/null
+++ b/numpy/f2py/__main__.py
@@ -0,0 +1,23 @@
+# See http://cens.ioc.ee/projects/f2py2e/
+import os, sys
+for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]:
+ try:
+ i=sys.argv.index("--"+mode)
+ del sys.argv[i]
+ break
+ except ValueError: pass
+os.environ["NO_SCIPY_IMPORT"]="f2py"
+if mode=="g3-numpy":
+ sys.stderr.write("G3 f2py support is not implemented, yet.\\n")
+ sys.exit(1)
+elif mode=="2e-numeric":
+ from f2py2e import main
+elif mode=="2e-numarray":
+ sys.argv.append("-DNUMARRAY")
+ from f2py2e import main
+elif mode=="2e-numpy":
+ from numpy.f2py import main
+else:
+ sys.stderr.write("Unknown mode: " + repr(mode) + "\\n")
+ sys.exit(1)
+main()
diff --git a/numpy/f2py/setup.py b/numpy/f2py/setup.py
index 2f1fd6a01..c63ab059a 100644
--- a/numpy/f2py/setup.py
+++ b/numpy/f2py/setup.py
@@ -29,6 +29,20 @@ from numpy.distutils.misc_util import Configuration
from __version__ import version
+
+def _get_f2py_shebang():
+ """ Return shebang line for f2py script
+
+ If we are building a binary distribution format, then the shebang line
+ should be ``#!python`` rather than ``#!`` followed by the contents of
+ ``sys.executable``.
+ """
+ if set(('bdist_wheel', 'bdist_egg', 'bdist_wininst',
+ 'bdist_rpm')).intersection(sys.argv):
+ return '#!python'
+ return '#!' + sys.executable
+
+
def configuration(parent_package='',top_path=None):
config = Configuration('f2py', parent_package, top_path)
@@ -52,32 +66,10 @@ def configuration(parent_package='',top_path=None):
if newer(__file__, target):
log.info('Creating %s', target)
f = open(target, 'w')
- f.write('''\
-#!%s
-# See http://cens.ioc.ee/projects/f2py2e/
-import os, sys
-for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]:
- try:
- i=sys.argv.index("--"+mode)
- del sys.argv[i]
- break
- except ValueError: pass
-os.environ["NO_SCIPY_IMPORT"]="f2py"
-if mode=="g3-numpy":
- sys.stderr.write("G3 f2py support is not implemented, yet.\\n")
- sys.exit(1)
-elif mode=="2e-numeric":
- from f2py2e import main
-elif mode=="2e-numarray":
- sys.argv.append("-DNUMARRAY")
- from f2py2e import main
-elif mode=="2e-numpy":
- from numpy.f2py import main
-else:
- sys.stderr.write("Unknown mode: " + repr(mode) + "\\n")
- sys.exit(1)
-main()
-'''%(sys.executable))
+ f.write(_get_f2py_shebang() + '\n')
+ mainloc = os.path.join(os.path.dirname(__file__), "__main__.py")
+ with open(mainloc) as mf:
+ f.write(mf.read())
f.close()
return target
diff --git a/numpy/tests/test_scripts.py b/numpy/tests/test_scripts.py
new file mode 100644
index 000000000..b48e3f3f7
--- /dev/null
+++ b/numpy/tests/test_scripts.py
@@ -0,0 +1,65 @@
+""" Test scripts
+
+Test that we can run executable scripts that have been installed with numpy.
+"""
+from __future__ import division, print_function, absolute_import
+
+import os
+from os.path import join as pathjoin, isfile, dirname, basename
+import sys
+from subprocess import Popen, PIPE
+import numpy as np
+from numpy.compat.py3k import basestring, asbytes
+from nose.tools import assert_equal
+from numpy.testing.decorators import skipif
+
+skipif_inplace = skipif(isfile(pathjoin(dirname(np.__file__), '..', 'setup.py')))
+
+def run_command(cmd, check_code=True):
+ """ Run command sequence `cmd` returning exit code, stdout, stderr
+
+ Parameters
+ ----------
+ cmd : str or sequence
+ string with command name or sequence of strings defining command
+ check_code : {True, False}, optional
+ If True, raise error for non-zero return code
+
+ Returns
+ -------
+ returncode : int
+ return code from execution of `cmd`
+ stdout : bytes (python 3) or str (python 2)
+ stdout from `cmd`
+ stderr : bytes (python 3) or str (python 2)
+ stderr from `cmd`
+
+ Raises
+ ------
+ RuntimeError
+ If `check_code` is True, and return code !=0
+ """
+ cmd = [cmd] if isinstance(cmd, basestring) else list(cmd)
+ if os.name == 'nt':
+ # Quote any arguments with spaces. The quotes delimit the arguments
+ # on Windows, and the arguments might be file paths with spaces.
+ # On Unix the list elements are each separate arguments.
+ cmd = ['"{0}"'.format(c) if ' ' in c else c for c in cmd]
+ proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
+ stdout, stderr = proc.communicate()
+ if proc.poll() == None:
+ proc.terminate()
+ if check_code and proc.returncode != 0:
+ raise RuntimeError('\n'.join(
+ ['Command "{0}" failed with',
+ 'stdout', '------', '{1}', '',
+ 'stderr', '------', '{2}']).format(cmd, stdout, stderr))
+ return proc.returncode, stdout, stderr
+
+
+@skipif_inplace
+def test_f2py():
+ # test that we can run f2py script
+ f2py_cmd = 'f2py' + basename(sys.executable)[6:]
+ code, stdout, stderr = run_command([f2py_cmd, '-v'])
+ assert_equal(stdout.strip(), asbytes('2'))
diff --git a/tools/travis-test.sh b/tools/travis-test.sh
index de078edf7..9a215314f 100755
--- a/tools/travis-test.sh
+++ b/tools/travis-test.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
set -ex
# setup env
@@ -117,10 +117,17 @@ fi
export PYTHON
export PIP
if [ -n "$USE_WHEEL" ] && [ $# -eq 0 ]; then
- $PIP install --upgrade pip
+ # Build wheel
$PIP install wheel
$PYTHON setup.py bdist_wheel
- $PIP install --pre --upgrade --find-links dist numpy
+ # Make another virtualenv to install into
+ virtualenv --python=python venv-for-wheel
+ . venv-for-wheel/bin/activate
+ # Move out of source directory to avoid finding local numpy
+ pushd dist
+ $PIP install --pre --upgrade --find-links . numpy
+ $PIP install nose
+ popd
run_test
elif [ "$USE_CHROOT" != "1" ] && [ "$USE_BENTO" != "1" ]; then
setup_base