8000 Merge pull request #6350 from matthew-brett/prepare-1.9.4 · numpy/numpy@c2b6ab9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2b6ab9

Browse files
committed
Merge pull request #6350 from matthew-brett/prepare-1.9.4
MRG: preparing for potential 1.9.4 release Fix f2py shebang line error for wheel installs.
2 parents edb902c + b064e4b commit c2b6ab9

File tree

5 files changed

+120
-29
lines changed

5 files changed

+120
-29
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ before_install:
3131
- ulimit -a
3232
- mkdir builds
3333
- pushd builds
34+
# Build into own virtualenv
35+
# We therefore control our own environment, avoid travis' numpy
36+
- virtualenv --python=python venv
37+
- source venv/bin/activate
3438
- pip install nose
3539
# pip install coverage
3640
- python -V

numpy/f2py/__main__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See http://cens.ioc.ee/projects/f2py2e/
2+
import os, sys
3+
for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]:
4+
try:
5+
i=sys.argv.index("--"+mode)
6+
del sys.argv[i]
7+
break
8+
except ValueError: pass
9+
os.environ["NO_SCIPY_IMPORT"]="f2py"
10+
if mode=="g3-numpy":
11+
sys.stderr.write("G3 f2py support is not implemented, yet.\\n")
12+
sys.exit(1)
13+
elif mode=="2e-numeric":
14+
from f2py2e import main
15+
elif mode=="2e-numarray":
16+
sys.argv.append("-DNUMARRAY")
17+
from f2py2e import main
18+
elif mode=="2e-numpy":
19+
from numpy.f2py import main
20+
else:
21+
sys.stderr.write("Unknown mode: " + repr(mode) + "\\n")
22+
sys.exit(1)
23+
main()

numpy/f2py/setup.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929

3030
from __version__ import version
3131

32+
33+
def _get_f2py_shebang():
34+
""" Return shebang line for f2py script
35+
36+
If we are building a binary distribution format, then the shebang line
37+
should be ``#!python`` rather than ``#!`` followed by the contents of
38+
``sys.executable``.
39+
"""
40+
if set(('bdist_wheel', 'bdist_egg', 'bdist_wininst',
41+
'bdist_rpm')).intersection(sys.argv):
42+
return '#!python'
43+
return '#!' + sys.executable
44+
45+
3246
def configuration(parent_package='',top_path=None):
3347
config = Configuration('f2py', parent_package, top_path)
3448

@@ -52,32 +66,10 @@ def generate_f2py_py(build_dir):
5266
if newer(__file__, target):
5367
log.info('Creating %s', target)
5468
f = open(target, 'w')
55-
f.write('''\
56-
#!%s
57-
# See http://cens.ioc.ee/projects/f2py2e/
58-
import os, sys
59-
for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]:
60-
try:
61-
i=sys.argv.index("--"+mode)
62-
del sys.argv[i]
63-
break
64-
except ValueError: pass
65-
os.environ["NO_SCIPY_IMPORT"]="f2py"
66-
if mode=="g3-numpy":
67-
sys.stderr.write("G3 f2py support is not implemented, yet.\\n")
68-
sys.exit(1)
69-
elif mode=="2e-numeric":
70-
from f2py2e import main
71-
elif mode=="2e-numarray":
72-
sys.argv.append("-DNUMARRAY")
73-
from f2py2e import main
74-
elif mode=="2e-numpy":
75-
from numpy.f2py import main
76-
else:
77-
sys.stderr.write("Unknown mode: " + repr(mode) + "\\n")
78-
sys.exit(1)
79-
main()
80-
'''%(sys.executable))
69+
f.write(_get_f2py_shebang() + '\n')
70+
mainloc = os.path.join(os.path.dirname(__file__), "__main__.py")
71+
with open(mainloc) as mf:
72+
f.write(mf.read())
8173
f.close()
8274
return target
8375

numpy/tests/test_scripts.py

Lines changed: 65 additions & 0 deletions
Or A3E2 iginal file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
""" Test scripts
2+
3+
Test that we can run executable scripts that have been installed with numpy.
4+
"""
5+
from __future__ import division, print_function, absolute_import
6+
7+
import os
8+
from os.path import join as pathjoin, isfile, dirname, basename
9+
import sys
10+
from subprocess import Popen, PIPE
11+
import numpy as np
12+
from numpy.compat.py3k import basestring, asbytes
13+
from nose.tools import assert_equal
14+
from numpy.testing.decorators import skipif
15+
16+
skipif_inplace = skipif(isfile(pathjoin(dirname(np.__file__), '..', 'setup.py')))
17+
18+
def run_command(cmd, check_code=True):
19+
""" Run command sequence `cmd` returning exit code, stdout, stderr
20+
21+
Parameters
22+
----------
23+
cmd : str or sequence
24+
string with command name or sequence of strings defining command
25+
check_code : {True, False}, optional
26+
If True, raise error for non-zero return code
27+
28+
Returns
29+
-------
30+
returncode : int
31+
return code from execution of `cmd`
32+
stdout : bytes (python 3) or str (python 2)
33+
stdout from `cmd`
34+
stderr : bytes (python 3) or str (python 2)
35+
stderr from `cmd`
36+
37+
Raises
38+
------
39+
RuntimeError
40+
If `check_code` is True, and return code !=0
41+
"""
42+
cmd = [cmd] if isinstance(cmd, basestring) else list(cmd)
43+
if os.name == 'nt':
44+
# Quote any arguments with spaces. The quotes delimit the arguments
45+
# on Windows, and the arguments might be file paths with spaces.
46+
# On Unix the list elements are each separate arguments.
47+
cmd = ['"{0}"'.format(c) if ' ' in c else c for c in cmd]
48+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
49+
stdout, stderr = proc.communicate()
50+
if proc.poll() == None:
51+
proc.terminate()
52+
if check_code and proc.returncode != 0:
53+
raise RuntimeError('\n'.join(
54+
['Command "{0}" failed with',
55+
'stdout', '------', '{1}', '',
56+
'stderr', '------', '{2}']).format(cmd, stdout, stderr))
57+
return proc.returncode, stdout, stderr
58+
59+
60+
@skipif_inplace
61+
def test_f2py():
62+
# test that we can run f2py script
63+
f2py_cmd = 'f2py' + basename(sys.executable)[6:]
64+
code, stdout, stderr = run_command([f2py_cmd, '-v'])
65+
assert_equal(stdout.strip(), asbytes('2'))

tools/travis-test.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -ex
33

44
# setup env
@@ -117,10 +117,17 @@ fi
117117
export PYTHON
118118
export PIP
119119
if [ -n "$USE_WHEEL" ] && [ $# -eq 0 ]; then
120-
$PIP install --upgrade pip
120+
# Build wheel
121121
$PIP install wheel
122122
$PYTHON setup.py bdist_wheel
123-
$PIP install --pre --upgrade --find-links dist numpy
123+
# Make another virtualenv to install into
124+
virtualenv --python=python venv-for-wheel
125+
. venv-for-wheel/bin/activate
126+
# Move out of source directory to avoid finding local numpy
127+
pushd dist
128+
$PIP install --pre --upgrade --find-links . numpy
129+
$PIP install nose
130+
popd
124131
run_test
125132
elif [ "$USE_CHROOT" != "1" ] && [ "$USE_BENTO" != "1" ]; then
126133
setup_base

0 commit comments

Comments
 (0)
0