make bbedit respect shebang line

108 views
Skip to first unread message

jjon

unread,
Jun 5, 2019, 3:58:34 PM6/5/19
to BBEdit Talk
I'm missing something obvious: Running python scripts from within BBedit 12.6.4 doesn't seem to respect anything I put in the shebang line. BBedit runs python3.7 no matter what. The entire contents of p3test.py is
help()

if I run it with command R the log file I get reads:
Welcome to Python 3.7's help utility!
... etc.

if I add shebang:
#!/usr/bin/env python2.7
help
()

I get the same thing. No matter what I put in the shebang line, BBedit runs python 3.7

What am I missing?

David Rostenne

unread,
Jun 5, 2019, 4:36:05 PM6/5/19
to bbe...@googlegroups.com
Hmm.

If I create a test.py file, with the only contents being help(), I get Welcome to Python 3.7's help utility!

If I choose the scripts menu item and run the Hello World.py, with the addition of help() I get 2.7. But I notice that this file has:
#!/usr/local/bin/python

I tried editing it to be #!/usr/local/bin/python3 and that gives me 3.7

So it seems the shebang is respected if you put the path to a binary in it.

Oh, no.. if I do the same with the test.py script it is always 3.7 no matter what I put in the shebang line.

Back to you!

Cheers,

Dave
> --
> This is the BBEdit Talk public discussion group. If you have a
> feature request or need technical support, please email
> "sup...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <https://www.twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To post to this group, send email to bbe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/bbedit.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/0cbc0c1c-efdb-4e39-a23f-c35eb8d1635f%40googlegroups.com.

Rich Siegel

unread,
Jun 5, 2019, 4:59:28 PM6/5/19
to bbe...@googlegroups.com
On 6/5/19 at 3:57 PM, crum...@gmail.com (jjon) wrote:

>I'm missing something obvious: Running python scripts from
>within BBedit 12.6.4 doesn't seem to respect anything I put in
>the shebang line. BBedit runs python3.7 no matter what. The
>entire contents of p3test.py is help()

In the 12.6.4 change notes:

* When running a Python script, if python3 is anywhere in your $PATH,
BBEdit will use it instead of python. While this is
generally useful
in a teaching environment, if you are using a custom Python
installation (such as Anaconda), it may prove inconvenient.
In that
case, disabling automatic use of python3 will help:

defaults write com.barebones.bbedit RunUsingPython3 -bool NO

Also, I believe that using "Run in Terminal" will always use the
#! line, so give that a try if the expert preference doesn't do
the job.

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Jon Crump

unread,
Jun 5, 2019, 5:36:41 PM6/5/19
to bbe...@googlegroups.com
Thanks for the quick response Rich. Yes, setting that boolean RunUsingPython3 "fixed" the problem. But now I can't get bbedit to use my python 3 installation if I put it in the shebang line. It's clear that where bbedit once respected the shebang line, now it does not. It seems like poor practice to teach your software to ignore explicit instructions right in the script it's supposed to run. Yes it's true that using "Run in Terminal" will respect shebang, but:
  1. I liked getting a log file right there in bbedit;
  2. this isn't the behavior I'm accustomed to; and
  3. it's inconvenient.
This does not seem like an improvement to me. It seems like a bug. Is there really no way to instruct bbedit which python installation to use without setting and resetting system-wide preferences from the command line?

J

–– Si vis pacembellum adflicta. ––


--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <https://www.twitter.com/bbedit>
---
You received this message because you are subscribed to a topic in the Google Groups "BBEdit Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bbedit/qWOsaWjiBYY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bbedit+un...@googlegroups.com.

To post to this group, send email to bbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.

Rich Siegel

unread,
Jun 6, 2019, 9:06:44 AM6/6/19
to bbe...@googlegroups.com
On 6/5/19 at 5:35 PM, crum...@gmail.com (Jon Crump) wrote:

>Thanks for the quick response Rich. Yes, setting that boolean
>RunUsingPython3 "fixed" the problem. But now I can't get bbedit to use my
>python 3 installation if I put it in the shebang line.

When running Perl, Python, or Ruby scripts, BBEdit does not use
or interpret the #! line. This decision goes back a long way in
time, I think to 11.0 but possibly before. (The issue this
solves is that everyone who's trying to learn Python uses the
same tutorial pattern which involves "#!/usr/bin/env python" or
something similar, then they install Python3 and wonder why
BBEdit doesn't use that.)

>It's clear that where bbedit once respected the shebang line, now it
>does not. It seems like poor practice to teach your software to ignore
>explicit instructions right in the script it's supposed to run. Yes
>it's true that using "Run in Terminal" will respect shebang, but:
>
>1. I liked getting a log file right there in bbedit;
>2. this isn't the behavior I'm accustomed to; and
>3. it's inconvenient.

I get this, and I'm sorry about it. But unfortunately we have to
deal with an enormous variety of use cases, and so the best we
can do is make the behavior adjustable when possible.

>This does not seem like an improvement to me. It seems like a bug. Is there
>really no way to instruct bbedit which python installation to use without
>setting and resetting system-wide preferences from the command line?

If you'll forgive the nit: the expert preference is
application-specific, and does not affect the system behavior.

That being said, there are numerous Python-specific ways to
control which Python installation and/or version gets used
without involving BBEdit at all; they're global and will affect
all Python execution.

If you have a use case that involves a need to frequently switch
between different versions of Python, please write to
<sup...@barebones.com> and describe your needs in detail, and
we'll see what we can do.

Anything that doesn't involve trying to read your mind at the
moment you press Command-R may be possible, but I can't make any
promises right now.

Jon Crump

unread,
Jun 7, 2019, 8:25:11 PM6/7/19
to bbe...@googlegroups.com
On Thu, Jun 6, 2019 at 6:06 AM Rich Siegel <sie...@barebones.com> wrote:
On 6/5/19 at 5:35 PM, crum...@gmail.com (Jon Crump) wrote:

>Thanks for the quick response Rich. Yes, setting that boolean
>RunUsingPython3 "fixed" the problem. But now I can't get bbedit to use my
>python 3 installation if I put it in the shebang line.

When running Perl, Python, or Ruby scripts, BBEdit does not use
or interpret the #! line. This decision goes back a long way in
time, I think to 11.0 but possibly before.

That's not really a very long way. I've used BBedit for a Long Time.
 
(The issue this
solves is that everyone who's trying to learn Python uses the
same tutorial pattern which involves "#!/usr/bin/env python" or
something similar, then they install Python3 and wonder why
BBEdit doesn't use that.)

Yes. That's what happened to me. But what I wonder is why BBEdit doesn't use what I tell it to use.
 
If you'll forgive the nit: the expert preference is
application-specific, and does not affect the system behavior.

Yes. I take your point, and gladly forgive. I just don't want to have to set and unset this every time I run a script.
 
If you have a use case that involves a need to frequently switch
between different versions of Python, please write to
<sup...@barebones.com> and describe your needs in detail, and
we'll see what we can do.

I only make an issue of it because my use case is as follows: I've got a couple of decades worth of python scripts, written for several different versions of Python, and I really liked being able to run them from within my text editor. That was a primary reason why I chose this text editor: because I could do that.

Now I can't.
 
Anything that doesn't involve trying to read your mind at the
moment you press Command-R may be possible, but I can't make any
promises right now.

Fortunately, BBEdit doesn't have to read my mind. It only has to read my script. My intentions are explicit right there at the top of each one.

J.

–– Si vis pacembellum adflicta. ––

PS. Please don't mistake my tone: I've long been a big fan of BBEdit, and I still am. Moreover I've always been happy with how helpful and responsive Bare Bones has always been. Kudos to all.

Christopher Stone

unread,
Jun 9, 2019, 12:26:39 PM6/9/19
to BBEdit-Talk
On 06/07/2019, at 18:31, Jon Crump <crum...@gmail.com> wrote:
Fortunately, BBEdit doesn't have to read my mind. It only has to read my script. My intentions are explicit right there at the top of each one.


Hey Folks,

Jeepers; somehow I missed this in release notes gone by...

A programming editor that refuses to run the code it's given to run is highly problematic.

While I'm completely sympathetic to the technical challenges the developers have to endure, it seems to me this is one place where there should be a compromise...

--
Best Regards,
Chris

David Rostenne

unread,
Jun 26, 2019, 6:43:36 PM6/26/19
to bbe...@googlegroups.com
.. and there’s a change in the latest release! See https://www.barebones.com/support/bbedit/notes-12.6.5.html for the full release notes!

> • When using a "Run" command for a file with a #! line, BBEdit will no longer attempt to run the file using the appropriate interpreter for the language (e.g. Python), and will instead ask the shell to run it directly. Thus, running a file like this:
>
> #!/usr/bin/env python
>
> import sys
>
> print(sys.version)
>
> will behave identically to using "Run In Terminal," and thus will always run the script using whatever python the system would have used on the command line.
>
> On the other hand, if you omit the #! line:
>
> import sys
>
> print(sys.version)
>
> Then BBEdit will make its best guess as to which python to use, based on the previously documented rules.
>
> Note: BBEdit will only run the file directly using the shell when using the "Run" (or "Run with Options") or "Run in Terminal" commands. When using "Check Syntax" or "Run in Debugger", BBEdit will continue to use its best guess for the language interpreter.
>
> This behavior is controlled by an expert preference. To force BBEdit to ignore the #! line:
>
> defaults write com.barebones.bbedit AlwaysUseShebangLineForWindowRun -bool NO

:-)

Thanks everyone at BareBones..

> On 9-June-2019, at 12:26 PM, Christopher Stone <listm...@suddenlink.net> wrote:
>
> On 06/07/2019, at 18:31, Jon Crump <crum...@gmail.com> wrote:
>> Fortunately, BBEdit doesn't have to read my mind. It only has to read my script. My intentions are explicit right there at the top of each one.
>
> Hey Folks,
>
> Jeepers; somehow I missed this in release notes gone by...
>
> A programming editor that refuses to run the code it's given to run is highly problematic.
>
> While I'm completely sympathetic to the technical challenges the developers have to endure, it seems to me this is one place where there should be a compromise...
>
> --
> Best Regards,
> Chris
>
>
> --
> This is the BBEdit Talk public discussion group. If you have a
> feature request or need technical support, please email
> "sup...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <https://www.twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To post to this group, send email to bbe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/bbedit.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/ECD1C2A8-81E4-41DD-B930-BD0DF38CC1E9%40suddenlink.net.

Reply all
Reply to author
Forward
0 new messages