Py-choose-shell is overriding `ipython' option with shebang

Bug #921990 reported by yagnesh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

lets say I have this in my .emacs

---------------------------------------------------
(require 'python-mode)
(add-hook 'python-mode-hook
           (lambda ()
             (setq py-shell-name "ipython")))
---------------------------------------------------

now I open a file with shebang containing

#!/usr/bin/env python3

and press C-c C-c it takes me to a python3 shell instead of ipython.
to make sure I verified with emacs -q and results the same.

What I expected is from
  ~ C-c C-c ~ to take me to *ipython* shell and inform
about my code is actually python3

Changed in python-mode:
milestone: none → 6.0.5
assignee: nobody → Andreas Roehler (a-roehler)
importance: Undecided → Medium
Revision history for this message
Andreas Roehler (a-roehler) wrote :

thank, Yagnesh,

pasting below from
https://code.launchpad.net/~yagnesh/python-mode/py-shell et al

> So you mean to say py-shell-name has no business in calling shell and its only for come as 'default' if all others fail?

Basically.
Having multiple choices, you can't avoid some hierarchical order making
a selection.

if hard-coded `py-shell-name' always should prevail, you must it change
when executing code designed for a different Python by shebang.

The assumtion so far: shebang knows best which Python to use. Therefor
preceding by default.

Will consider possible change of py-execute-region permitting to enforce
a shell independent from shebang, accepting an optional argument "execute-with-this-shell-instead-of-shebang",
would replace "&optional async"

Revision history for this message
yagnesh (yagnesh) wrote : Re: [Bug 921990] Re: Py-choose-shell is overriding `ipython' option with shebang

On 01/26/2012 07:26 PM, Andreas Roehler wrote:
> thank, Yagnesh,
>
> pasting below from
> https://code.launchpad.net/~yagnesh/python-mode/py-shell et al
>
>> So you mean to say py-shell-name has no business in calling shell and
> its only for come as 'default' if all others fail?
>
> Basically.
> Having multiple choices, you can't avoid some hierarchical order making
> a selection.
>
> if hard-coded `py-shell-name' always should prevail, you must it change
> when executing code designed for a different Python by shebang.
>
> The assumtion so far: shebang knows best which Python to use. Therefor
> preceding by default.
>
> Will consider possible change of py-execute-region permitting to enforce
> a shell independent from shebang, accepting an optional argument "execute-with-this-shell-instead-of-shebang",
> would replace "&optional async"

Its seems fine reasonable. May be providing a customizing hook just
before calling the execution would shut up raising voices (like me)

Thanks

PS: I got to say this, you are super fast

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Yagnesh,

can you try the new design?

Thanks,
Andreas

Changed in python-mode:
status: New → Fix Committed
Revision history for this message
yagnesh (yagnesh) wrote :

On 01/27/2012 11:26 PM, Andreas Roehler wrote:
> Hi Yagnesh,
>
> can you try the new design?
>
> Thanks,
> Andreas
>
> ** Changed in: python-mode
> Status: New => Fix Committed
>
Here are my observations:

context:
- python-mode.el from bzr trunk
    (user configured `py-shell-name' is not honored by
`py-guess-default', lp:920079, fixed)
- emacs 24 from bzr-trunk as well.
- Test python3 file called bug.el contents are the following.
-------------------------------------
#!/usr/bin/env python3
# File: bug.py

a = "b"
print(a)

# bug.py ends here
-------------------------------------

Every time I opened my emacs 24 (from latest head) like this
emacs -q -l ~/.emacs.d/minimal.el bug.py

Case 1: If I dont set py-shell-name at all.
=============================================
observation:
- as I opened the file, I see a python2 shell (comint-run)
   Buffer.
- Pressing C-c C-c takes me to that python2 shell

Remarks:
- as I open the file it, it may open a python3 shell instead of and
   python2.

Case 2: If I set to py-shell-name to "ipython"
=============================================

Observation:
- as I opened the file, I see a python2 shell (comint-run)
   Buffer.
- pressing C-c C-c taking to *Ipython* buffer with the following error
message.

,----
| In [1]:
---------------------------------------------------------------------------
| NameError Traceback (most recent call
last)
| /home/yagnesh/tmp/<ipython-input-1-b069c4a96c1a> in <module>()
| ----> 1 execfile(r'/tmp/IPython31683Bz7.py') # PYTHON-MODE
|
| NameError: name 'execfile' is not defined
`----

Remarks:
- again it should not have opened a python2 shell
- at least pressing C-c C-c should not give any error.
   since its python3 the C-c C-c should have sent exec instead execfile

Case 3: If I set to py-shell-name to "ipython3"
=============================================
Observation:
- as I opened the file, I see a python2 shell (comint-run)
   Buffer.
- pressing C-c C-c taking to *Ipython3* buffer executing execution is
fine.

Remarks:
- and again it should not have opened a python2 shell

The end for now.

Finally, I think this is first level problem user will face, if we clear
this one we can go debugging on to the next problems. apologies for
not able to submit a patch.

Thanks again
Yagnesh

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Yagnesh,

thanks a lot for your care.

Please open a new record for this.

Looks like mixed issues inside which must not affect the original one.

Please note: only py-execute-region-default will enforce the default shell disregarding shebang.

Andreas

Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.