Repository: numpy/numpy

Issue:
Numpy contains shebang pointing to /usr/bin/python which are problematic
Hi

We are packaging numpy pre-installed in a virtualenv using a rpm. RPM has a "convenient" feature to automatically scan for script files with shebang and adding those as requirements of the resulting rpm. For more information, see [this blog post](http://www.legendiary.at/2013/03/20/rpmbuild-shebang-auto-required-packages/).

Most of the numpy scripts use

````bash
#!/usr/bin/env python
````

which rpm resolves to whatever is in the PATH.

However, some of the packages point to hard-coded path of python:
````bash
$ grep '^#!' **/*.py|grep -v '/usr/bin/env python'
numpy/core/tests/test_arrayprint.py:#!/usr/bin/python
numpy/distutils/conv_template.py:#!/usr/bin/python
numpy/distutils/from_template.py:#!/usr/bin/python
````

I would propose that the above scripts would be changed to use `#!/usr/bin/env python`.

This change would make the rpm process resolve python and bash using whatever is in the path. For example, with CentOS 6, the system python (in `/usr/bin/python`) is python 2.6, although the `python` in PATH could very well be `python2.7` or newer. In our case the virtualenv is activated during the build, and thus `#!/usr/bin/env python` would resolve to the correct interpreter.

The additional benefit is that the scripts are more cross-platform.

I'm willing to submit a pull requests if you agree with the fix?

Best,
Sami Salonen


Scipy issue regarding the same matter: https://github.com/scipy/scipy/issues/6961
Pandas issue regarding the same matter: https://github.com/pandas-dev/pandas/issues/15131


Discussion:
Go for it.

Resolving patch:
diff --git a/numpy/distutils/conv_template.py b/numpy/distutils/conv_template.py
--- a/numpy/distutils/conv_template.py
+++ b/numpy/distutils/conv_template.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 """
 takes templated file .xxx.src and produces .xxx file  where .xxx is
 .i or .c or .h, using the following template rules
diff --git a/numpy/distutils/from_template.py b/numpy/distutils/from_template.py
--- a/numpy/distutils/from_template.py
+++ b/numpy/distutils/from_template.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 """
 
 process_file(filename)


Test patch:
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 # -*- coding: utf-8 -*-
 from __future__ import division, absolute_import, print_function
 
diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py
--- a/numpy/distutils/tests/test_misc_util.py
+++ b/numpy/distutils/tests/test_misc_util.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 from __future__ import division, absolute_import, print_function
 
 from os.path import join, sep, dirname
diff --git a/numpy/fft/tests/test_helper.py b/numpy/fft/tests/test_helper.py
--- a/numpy/fft/tests/test_helper.py
+++ b/numpy/fft/tests/test_helper.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 """Test functions for fftpack.helper module
 
 Copied from fftpack.helper by Pearu Peterson, October 2005