diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-08-28 11:16:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-28 11:16:43 -0500 |
commit | 14a3ac9586f26929b696b9a38afb155d37cef3b0 (patch) | |
tree | ffe8df776133f2fb29730b58a3eef60e9da40250 /numpy | |
parent | ac4d4807c5b4b61aae59a656beb1b3feed59386b (diff) | |
parent | ec7c846cf111114a28e9993fb9335f3c63c97fc7 (diff) | |
download | numpy-14a3ac9586f26929b696b9a38afb155d37cef3b0.tar.gz |
Merge pull request #11802 from charris/f2py-console-script
ENH: Use entry_points to install the f2py scripts.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/f2py/__main__.py | 25 | ||||
-rwxr-xr-x | numpy/f2py/f2py2e.py | 24 | ||||
-rw-r--r-- | numpy/f2py/setup.py | 50 | ||||
-rw-r--r-- | numpy/tests/test_scripts.py | 45 |
4 files changed, 50 insertions, 94 deletions
diff --git a/numpy/f2py/__main__.py b/numpy/f2py/__main__.py index cb8f261c1..6eff41099 100644 --- a/numpy/f2py/__main__.py +++ b/numpy/f2py/__main__.py @@ -1,27 +1,6 @@ # See http://cens.ioc.ee/projects/f2py2e/ from __future__ import division, print_function -import os -import 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) +from f2py2e import main + main() diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py index 254f99966..8750ed0b3 100755 --- a/numpy/f2py/f2py2e.py +++ b/numpy/f2py/f2py2e.py @@ -644,13 +644,25 @@ def main(): from numpy.distutils.system_info import show_all show_all() return + + # Probably outdated options that were not working before 1.16 + if '--g3-numpy' in sys.argv[1:]: + sys.stderr.write("G3 f2py support is not implemented, yet.\\n") + sys.exit(1) + elif '--2e-numeric' in sys.argv[1:]: + sys.argv.remove('--2e-numeric') + elif '--2e-numarray' in sys.argv[1:]: + # Note that this errors becaust the -DNUMARRAY argument is + # not recognized. Just here for back compatibility and the + # error message. + sys.argv.append("-DNUMARRAY") + sys.argv.remove('--2e-numarray') + elif '--2e-numpy' in sys.argv[1:]: + sys.argv.remove('--2e-numpy') + else: + pass + if '-c' in sys.argv[1:]: run_compile() else: run_main(sys.argv[1:]) - -# if __name__ == "__main__": -# main() - - -# EOF diff --git a/numpy/f2py/setup.py b/numpy/f2py/setup.py index 73cb3b8bf..e95b9584f 100644 --- a/numpy/f2py/setup.py +++ b/numpy/f2py/setup.py @@ -18,8 +18,6 @@ Pearu Peterson """ from __future__ import division, print_function -__version__ = "$Id: setup.py,v 1.32 2005/01/30 17:22:14 pearu Exp $" - import os import sys from distutils.dep_util import newer @@ -27,60 +25,22 @@ from numpy.distutils import log from numpy.distutils.core import setup 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 +from __version__ import version def configuration(parent_package='', top_path=None): config = Configuration('f2py', parent_package, top_path) - config.add_data_dir('tests') - - config.add_data_files('src/fortranobject.c', - 'src/fortranobject.h', - ) - - config.make_svn_version_py() - - def generate_f2py_py(build_dir): - f2py_exe = 'f2py' + os.path.basename(sys.executable)[6:] - if f2py_exe[-4:] == '.exe': - f2py_exe = f2py_exe[:-4] + '.py' - if 'bdist_wininst' in sys.argv and f2py_exe[-3:] != '.py': - f2py_exe = f2py_exe + '.py' - target = os.path.join(build_dir, f2py_exe) - if newer(__file__, target): - log.info('Creating %s', target) - f = open(target, 'w') - 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 - - config.add_scripts(generate_f2py_py) - - log.info('F2PY Version %s', config.get_version()) - + config.add_data_files( + 'src/fortranobject.c', + 'src/fortranobject.h') return config + if __name__ == "__main__": config = configuration(top_path='') - print('F2PY Version', version) config = config.todict() config['download_url'] = "http://cens.ioc.ee/projects/f2py2e/2.x"\ diff --git a/numpy/tests/test_scripts.py b/numpy/tests/test_scripts.py index ee09390c7..26e3ea745 100644 --- a/numpy/tests/test_scripts.py +++ b/numpy/tests/test_scripts.py @@ -62,32 +62,37 @@ def run_command(cmd, check_code=True): @pytest.mark.skipif(is_inplace, reason="Cannot test f2py command inplace") def test_f2py(): # test that we can run f2py script + + def try_f2py_commands(cmds): + success = 0 + for f2py_cmd in cmds: + try: + code, stdout, stderr = run_command([f2py_cmd, '-v']) + assert_equal(stdout.strip(), b'2') + success += 1 + except Exception: + pass + return success + if sys.platform == 'win32': + # Only the single 'f2py' script is installed in windows. exe_dir = dirname(sys.executable) - if exe_dir.endswith('Scripts'): # virtualenv - f2py_cmd = r"%s\f2py.py" % exe_dir + f2py_cmds = [os.path.join(exe_dir, 'f2py')] else: - f2py_cmd = r"%s\Scripts\f2py.py" % exe_dir - - code, stdout, stderr = run_command([sys.executable, f2py_cmd, '-v']) - success = stdout.strip() == b'2' - assert_(success, "Warning: f2py not found in path") + f2py_cmds = [os.path.join(exe_dir, "Scripts", 'f2py')] + success = try_f2py_commands(f2py_cmds) + msg = "Warning: f2py not found in path" + assert_(success == 1, msg) else: + # Three scripts are installed in Unix-like systems: + # 'f2py', 'f2py{major}', and 'f2py{major.minor}'. For example, + # if installed with python3.7 the scripts would be named + # 'f2py', 'f2py3', and 'f2py3.7'. version = sys.version_info major = str(version.major) minor = str(version.minor) - f2py_cmds = ('f2py', 'f2py' + major, 'f2py' + major + '.' + minor) - success = False - - for f2py_cmd in f2py_cmds: - try: - code, stdout, stderr = run_command([f2py_cmd, '-v']) - assert_equal(stdout.strip(), b'2') - success = True - break - except Exception: - pass - msg = "Warning: neither %s nor %s nor %s found in path" % f2py_cmds - assert_(success, msg) + success = try_f2py_commands(f2py_cmds) + msg = "Warning: not all of %s, %s, and %s are found in path" % f2py_cmds + assert_(success == 3, msg) |