Repository: scipy/scipy

Issue:
Scipy contains shebang pointing to /usr/bin/python and /bin/bash which are problematic
Hi

We are packaging scipy 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 scipy 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'
scipy/special/generate_ufuncs.py:#!/usr/bin/python
scipy/special/tests/test_basic.py:#!   Means test is segfaulting
scipy/special/utils/makenpz.py:#!/bin/bash
tools/win32/detect_cpu_extensions_wine.py:#!/usr/bin/python
````

I would propose that the above scripts (excluding `test_basic.py` which does not really have a shebang) would be changed to use `#!/usr/bin/env python` and `#!/usr/bin/env bash`, as approriate. 

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

Numpy issue of the same topic: https://github.com/numpy/numpy/issues/8472
Pandas issue of the same topic: https://github.com/pandas-dev/pandas/issues/15131



Discussion:
There's probably no problem in doing that. Note however that those
scripts are never run unless you are doing development.

Thanks for the quick response!

Yeah, I understand they are meant for development only. I believe they are still marked to be installed and thus cause the described issue with our way of rpm packaging...

I will come back with PR.

Best
Sami
At the same time, you can perhaps remove all shebang lines from the "test_*.py" files --- these files should never have executable bit set.

Resolving patch:
diff --git a/scipy/special/generate_ufuncs.py b/scipy/special/generate_ufuncs.py
--- a/scipy/special/generate_ufuncs.py
+++ b/scipy/special/generate_ufuncs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 """
 generate_ufuncs.py
 
diff --git a/scipy/special/utils/makenpz.py b/scipy/special/utils/makenpz.py
--- a/scipy/special/utils/makenpz.py
+++ b/scipy/special/utils/makenpz.py
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 """
 makenpz.py DIRECTORY
 
diff --git a/tools/win32/detect_cpu_extensions_wine.py b/tools/win32/detect_cpu_extensions_wine.py
--- a/tools/win32/detect_cpu_extensions_wine.py
+++ b/tools/win32/detect_cpu_extensions_wine.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 """
 Detect which x86 CPU extension instructions the given scipy install uses.
 This file can be used in the release process to check that the nosse installer


Test patch:
diff --git a/scipy/cluster/tests/test_hierarchy.py b/scipy/cluster/tests/test_hierarchy.py
--- a/scipy/cluster/tests/test_hierarchy.py
+++ b/scipy/cluster/tests/test_hierarchy.py
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 #
 # Author: Damian Eads
 # Date: April 17, 2008
diff --git a/scipy/cluster/tests/test_vq.py b/scipy/cluster/tests/test_vq.py
--- a/scipy/cluster/tests/test_vq.py
+++ b/scipy/cluster/tests/test_vq.py
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 
 from __future__ import division, print_function, absolute_import
 
diff --git a/scipy/fftpack/tests/test_basic.py b/scipy/fftpack/tests/test_basic.py
--- a/scipy/fftpack/tests/test_basic.py
+++ b/scipy/fftpack/tests/test_basic.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Created by Pearu Peterson, September 2002
 
 from __future__ import division, print_function, absolute_import
diff --git a/scipy/fftpack/tests/test_helper.py b/scipy/fftpack/tests/test_helper.py
--- a/scipy/fftpack/tests/test_helper.py
+++ b/scipy/fftpack/tests/test_helper.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Created by Pearu Peterson, September 2002
 
 from __future__ import division, print_function, absolute_import
diff --git a/scipy/fftpack/tests/test_pseudo_diffs.py b/scipy/fftpack/tests/test_pseudo_diffs.py
--- a/scipy/fftpack/tests/test_pseudo_diffs.py
+++ b/scipy/fftpack/tests/test_pseudo_diffs.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Created by Pearu Peterson, September 2002
 
 from __future__ import division, print_function, absolute_import
diff --git a/scipy/fftpack/tests/test_real_transforms.py b/scipy/fftpack/tests/test_real_transforms.py
--- a/scipy/fftpack/tests/test_real_transforms.py
+++ b/scipy/fftpack/tests/test_real_transforms.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 from __future__ import division, print_function, absolute_import
 
 from os.path import join, dirname
diff --git a/scipy/interpolate/tests/test_fitpack2.py b/scipy/interpolate/tests/test_fitpack2.py
--- a/scipy/interpolate/tests/test_fitpack2.py
+++ b/scipy/interpolate/tests/test_fitpack2.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Created by Pearu Peterson, June 2003
 from __future__ import division, print_function, absolute_import
 
diff --git a/scipy/interpolate/tests/test_rbf.py b/scipy/interpolate/tests/test_rbf.py
--- a/scipy/interpolate/tests/test_rbf.py
+++ b/scipy/interpolate/tests/test_rbf.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Created by John Travers, Robert Hetland, 2007
 """ Test functions for rbf module """
 from __future__ import division, print_function, absolute_import
diff --git a/scipy/io/arff/tests/test_arffread.py b/scipy/io/arff/tests/test_arffread.py
--- a/scipy/io/arff/tests/test_arffread.py
+++ b/scipy/io/arff/tests/test_arffread.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 from __future__ import division, print_function, absolute_import
 
 import datetime
diff --git a/scipy/io/matlab/tests/test_mio.py b/scipy/io/matlab/tests/test_mio.py
--- a/scipy/io/matlab/tests/test_mio.py
+++ b/scipy/io/matlab/tests/test_mio.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: latin-1 -*-
 ''' Nose test generators
 
diff --git a/scipy/io/matlab/tests/test_mio_funcs.py b/scipy/io/matlab/tests/test_mio_funcs.py
--- a/scipy/io/matlab/tests/test_mio_funcs.py
+++ b/scipy/io/matlab/tests/test_mio_funcs.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 ''' Jottings to work out format for __function_workspace__ matrix at end
 of mat file.
 
diff --git a/scipy/io/tests/test_mmio.py b/scipy/io/tests/test_mmio.py
--- a/scipy/io/tests/test_mmio.py
+++ b/scipy/io/tests/test_mmio.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 from __future__ import division, print_function, absolute_import
 
 from tempfile import mkdtemp, mktemp
diff --git a/scipy/linalg/tests/test_basic.py b/scipy/linalg/tests/test_basic.py
--- a/scipy/linalg/tests/test_basic.py
+++ b/scipy/linalg/tests/test_basic.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Created by: Pearu Peterson, March 2002
 #
diff --git a/scipy/linalg/tests/test_blas.py b/scipy/linalg/tests/test_blas.py
--- a/scipy/linalg/tests/test_blas.py
+++ b/scipy/linalg/tests/test_blas.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Created by: Pearu Peterson, April 2002
 #
diff --git a/scipy/linalg/tests/test_lapack.py b/scipy/linalg/tests/test_lapack.py
--- a/scipy/linalg/tests/test_lapack.py
+++ b/scipy/linalg/tests/test_lapack.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Created by: Pearu Peterson, September 2002
 #
diff --git a/scipy/linalg/tests/test_matfuncs.py b/scipy/linalg/tests/test_matfuncs.py
--- a/scipy/linalg/tests/test_matfuncs.py
+++ b/scipy/linalg/tests/test_matfuncs.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Created by: Pearu Peterson, March 2002
 #
diff --git a/scipy/optimize/tests/test_zeros.py b/scipy/optimize/tests/test_zeros.py
--- a/scipy/optimize/tests/test_zeros.py
+++ b/scipy/optimize/tests/test_zeros.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 from __future__ import division, print_function, absolute_import
 
 from math import sqrt, exp, sin, cos
diff --git a/scipy/sparse/linalg/eigen/lobpcg/tests/test_lobpcg.py b/scipy/sparse/linalg/eigen/lobpcg/tests/test_lobpcg.py
--- a/scipy/sparse/linalg/eigen/lobpcg/tests/test_lobpcg.py
+++ b/scipy/sparse/linalg/eigen/lobpcg/tests/test_lobpcg.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 """ Test functions for the sparse.linalg.eigen.lobpcg module
 """
 from __future__ import division, print_function, absolute_import
diff --git a/scipy/sparse/linalg/isolve/tests/test_iterative.py b/scipy/sparse/linalg/isolve/tests/test_iterative.py
--- a/scipy/sparse/linalg/isolve/tests/test_iterative.py
+++ b/scipy/sparse/linalg/isolve/tests/test_iterative.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 """ Test functions for the sparse.linalg.isolve module
 """
 
diff --git a/scipy/sparse/linalg/isolve/tests/test_lgmres.py b/scipy/sparse/linalg/isolve/tests/test_lgmres.py
--- a/scipy/sparse/linalg/isolve/tests/test_lgmres.py
+++ b/scipy/sparse/linalg/isolve/tests/test_lgmres.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 """Tests for the linalg.isolve.lgmres module
 """
 
diff --git a/scipy/sparse/linalg/tests/test_matfuncs.py b/scipy/sparse/linalg/tests/test_matfuncs.py
--- a/scipy/sparse/linalg/tests/test_matfuncs.py
+++ b/scipy/sparse/linalg/tests/test_matfuncs.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Created by: Pearu Peterson, March 2002
 #
diff --git a/scipy/spatial/tests/test_distance.py b/scipy/spatial/tests/test_distance.py
--- a/scipy/spatial/tests/test_distance.py
+++ b/scipy/spatial/tests/test_distance.py
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 #
 # Author: Damian Eads
 # Date: April 17, 2008