[PATCH] setup.py: Preserve the '#!/usr/bin/env python' stanza

136 views
Skip to first unread message

David Aguilar

unread,
Jul 1, 2009, 8:08:54 PM7/1/09
to nose...@googlegroups.com, jpeller...@gmail.com, David Aguilar
distutils automatically replaces shebang lines with the
full path to Python, which invalidates our #!/usr/bin/env python
trick. Disable the distutils "feature" by replacing the regex
it uses to detect the first line of a Python script.

Signed-off-by: David Aguilar <dav...@gmail.com>
---
setup.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/setup.py b/setup.py
index 72e30c9..589f0fa 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,11 @@ try:
test_suite = 'nose.collector',
)
except ImportError:
+ import re
from distutils.core import setup
+ from distutils.command import build_scripts
+ build_scripts.first_line_re = re.compile('^should not match$')
+
addl_args = dict(
packages = ['nose', 'nose.ext', 'nose.plugins'],
scripts = ['bin/nosetests'],
--
1.6.3.1

Kumar McMillan

unread,
Jul 6, 2009, 10:40:54 AM7/6/09
to nose...@googlegroups.com, jpeller...@gmail.com, David Aguilar
This patch would break installation within a virtualenv, which relies
on distutils' behavior of setting the explit path to the Python
interpreter (and is generally safer, imo). I'd suggest instead that
you make yourself a buildout recipe that creates a custom script with
the bin/env python shebang

David Aguilar

unread,
Jul 6, 2009, 8:31:08 PM7/6/09
to Kumar McMillan, nose...@googlegroups.com, jpeller...@gmail.com
On Mon, Jul 06, 2009 at 09:40:54AM -0500, Kumar McMillan wrote:
> This patch would break installation within a virtualenv, which relies
> on distutils' behavior of setting the explit path to the Python
> interpreter (and is generally safer, imo). I'd suggest instead that
> you make yourself a buildout recipe that creates a custom script with
> the bin/env python shebang

Thanks for the feedback.

Is 'python' not in the virtualenv machine's path?
(just curious).
--
David

Kumar McMillan

unread,
Jul 7, 2009, 12:49:17 AM7/7/09
to David Aguilar, nose...@googlegroups.com, jpeller...@gmail.com
On Mon, Jul 6, 2009 at 7:31 PM, David Aguilar<dav...@gmail.com> wrote:
> On Mon, Jul 06, 2009 at 09:40:54AM -0500, Kumar McMillan wrote:
>> This patch would break installation within a virtualenv, which relies
>> on distutils' behavior of setting the explit path to the Python
>> interpreter (and is generally safer, imo).  I'd suggest instead that
>> you make yourself a buildout recipe that creates a custom script with
>> the bin/env python shebang
>
> Thanks for the feedback.
>
> Is 'python' not in the virtualenv machine's path?
> (just curious).

it is, but if you run a script you might not want the result of what
env python tells you. For example:

/projects/my-env/bin/nosetests

would invoke bin/env python and that would probably be
/usr/local/bin/python which is not what you want. The shebang on the
script would be /projects/my-env/bin/python which is what you'd want
for the script to run in the virtualenv

Also, there is no standard about /usr/bin/env. It is not included by
default on some BSD systems, for examples. Then some systems put it
in /usr/local/bin/env, it is not very reliable as a shebang. Notice
that I haven't even brought up Windows :) That's only because
distutils does not generate scripts that run on Windows. You need to
use setuptools for that.
Reply all
Reply to author
Forward
0 new messages