diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-08-22 11:57:48 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-08-23 13:51:42 -0600 |
commit | f22a33b71dc767d81ed60f40c3b84456d2a33f79 (patch) | |
tree | bc0c5b82c765cca7fd5272a1fc45e100d2cc8f12 /numpy/tests/test_scripts.py | |
parent | d0a0e38815206ee72413942af7f1241e85ec8051 (diff) | |
download | numpy-f22a33b71dc767d81ed60f40c3b84456d2a33f79.tar.gz |
ENH: Use entry_points to install the f2py scripts.
This adds entry_points for the f2py scripts. The installed scripts
differ between Windows and other environments.
* On Windows, the only script installed is 'f2py'. This works well in
that environment because each Python version is installed in its own
directory, making it easy to keep the differing script versions
separate.
* Otherwise, three scripts are installed, 'f2py', 'f2py' + 'minor', and
'f2py' + 'major.minor'. For instance, if Numpy is installed by
Python 2.7, then the installed scripts will be named 'f2py', 'f2py2',
and 'f2py2.7'. That naming scheme is used for back compatibility, and
also so that more than one Python version can be dealt with in a way
common to many Linux distros. Note that 'f2py' will always point to
the latest install and 'f2py(2|3)' to the latest Python (2|3) install
The script tests have been modified to check for the new environment
and the code previously used to install the scripts has been removed.
Diffstat (limited to 'numpy/tests/test_scripts.py')
-rw-r--r-- | numpy/tests/test_scripts.py | 45 |
1 files changed, 25 insertions, 20 deletions
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) |