atom-community / atom-script

:runner: Run ( scripts | selections | source ) in Atom
https://atom.io/packages/script
MIT License
733 stars 269 forks source link

Feature Request: Respect Shebang #152

Closed Bengt closed 10 years ago

Bengt commented 10 years ago

atom-script always starts my Python scripts with the default python, even if i declare a shebang.

#!/usr/bin/env python3
import sys
print(sys.version_info)

and

#!/bin/python3
import sys
print(sys.version_info)

yield

sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0)

Notice that it is common for python scripts to be only compatible with one major version, so a (global) configuration would not solve the issue.

erran commented 10 years ago

I'll take a look at this. I know #5 references virtualenv at one point. I use rbenv myself for Ruby and run from the command line which means I never see the conflicting paths though. Python is an interesting use case (the name of the executable that is).

Bengt commented 10 years ago

Notice that "Blanks after ! are OK.", so these variants should work, too:

#! /usr/bin/env python
#! /bin/python

Additionally, command line flags might be given to the interpreter: Some interesting cases are these:

#!/bin/python --version
#!/bin/python --
#!/bin/python -
#!/bin/python -3
#!/bin/python -c
#!/bin/python -O
#!/bin/python -OO
#!/bin/python -Q new

Also there are multiline shebangs. To start python from a polyglot bash/python file:

#!/bin/bash
"exec" "python" "$0"

print "Hello World"
rgbkrk commented 10 years ago

I vote the very last one just gets handled by the bash handler. Why would anyone use that one?

Bengt commented 10 years ago

@rgbkrk polyglot files can exploit features of both programming languages. For example bash knows $0 to be the filename, while the embedded language might not. This example is the not really useful but demonstrates the how to do this in bash/python. Python has in fact access to the filename sys.args[0], but other scripting languages do not. Perhaps there is something bash has access to and Python does not, but I do not know about such a thing. In any case, I think executing the file as a bash script should work just fine without action from atom-script's side.