From andreas.roehler at online.de Sat Oct 17 17:54:51 2009 From: andreas.roehler at online.de (Andreas Roehler) Date: Sat, 17 Oct 2009 17:54:51 +0200 Subject: [Python-mode] [Bug 450552] [NEW] python-mode breaks for python 3 In-Reply-To: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> Message-ID: <4AD9E8CB.7030800@online.de> Rustom wrote: > Public bug reported: > > python 3 has removed execfile > This makes python-mode stop working > > In function py-execute-file changing the line > > (cmd (format "execfile(r'%s') # PYTHON-MODE\n" filename))) > > to > (cmd (format "exec(open(r'%s').read()) # PYTHON-MODE\n" filename))) > > seems to solve the problem > > ** Affects: python-mode > Importance: Undecided > Status: New > IMO it's not to cure by changing a line in general. More bugs will be around due to different flavours of python. Versions of python 2.4.+ are in use still AFAIK. 2.5.+ or 2.6.+ will remain widely used Will a single python-mode be able to cope with this differences? IMHO: yes, however it must to address some issues. Herewith some outlines what seems necessary: - specifying by a variable the version where edits are for (customizable) - some guessing, which python-version might be in used, if user didn't set it - displaying python-versions-variable in mode-line - auto-adapting code, editing and execution resp. to the mentioned version. - possible switch between versions-specifics, updating the modeline etc. Introducing a first item in this line might read: (defcustom py-adressed-python-version "" "*With different Python versions, changes have been made, which affect python execution as editing likewise. If a version is specified here, python-mode will adapt its proceeding to it. Otherwise python-mode will try some guess from the installed system. You may switch the addressed python-version with M-x py-switch-addressed-version during your emacs-session. " :type 'string :group 'python) Any hints, objections, ideas? Thanks! Andreas -- https://code.launchpad.net/s-x-emacs-werkstatt/ http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/ From barry at python.org Sat Oct 17 18:10:41 2009 From: barry at python.org (Barry Warsaw) Date: Sat, 17 Oct 2009 12:10:41 -0400 Subject: [Python-mode] [Bug 450552] [NEW] python-mode breaks for python 3 In-Reply-To: <4AD9E8CB.7030800@online.de> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <4AD9E8CB.7030800@online.de> Message-ID: <2B8F4CC0-E6B8-4E4A-A28D-84072DD53E8A@python.org> On Oct 17, 2009, at 11:54 AM, Andreas Roehler wrote: > > (defcustom py-adressed-python-version "" > "*With different Python versions, changes have been made, which > affect python execution as editing likewise. > If a version is specified here, python-mode will adapt its > proceeding to it. > Otherwise python-mode will try some guess from the installed system. > You may switch the addressed python-version with M-x py-switch- > addressed-version during your emacs-session. " > :type 'string > :group 'python) > > Any hints, objections, ideas? I'd definitely love to see some enhancements to python-mode to deal with Python 3, but of course I have no time for that myself. ;) I'd suggest two variables: (defvar py-python-major-version ...) This would be a buffer-local variable, defaulting to "2", specifying the Python major version of the code in the current buffer. (defcustom py-guess-python-version ...) This would be a global customizable variable specifying whether to apply heuristics to guess the py-python-major-version when a buffer is visited. It should probably default to t. +1 for working on this! -Barry From andreas.roehler at online.de Tue Oct 20 10:29:16 2009 From: andreas.roehler at online.de (Andreas Roehler) Date: Tue, 20 Oct 2009 10:29:16 +0200 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: <20091019130931.3875.15493.malone@gangotri.canonical.com> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> Message-ID: <4ADD74DC.1010806@online.de> Rustom wrote: > Right now the mc Im on does not have python 2.x and python3 > > But when I was on a debian box with 2.5 and 3 > changing > > (cmd (format "execfile(r'%s') # PYTHON-MODE\n" filename))) > > to > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) # > PYTHON-MODE\n" filename filename))) > > [ not > > (cmd (format "exec(open(r'%s').read()) # PYTHON-MODE\n" filename))) > as my original post suggested] > > seemed to work for both 2.5 and 3 > > Whether other changes from 2.x to 3 will introduce breakage in python- > mode I dont know > > The more important question remaining about my suggested fix is about windows. > Evidently there is some stupidity that exec expects its input to have unix line endings even on windows so the original code may not work on windows but the one with compile should. > > But Ive not tested on windows > Hi Rustom, looks like good news. Think you are right. Checked a little bit with Python 2.5.1 on Linux 2.6.22.19-0.2-default #1 SMP 2008-12-18 10:17:03 +0100 i686 athlon i386 GNU/Linux works fine AFAIS. What puzzles me still is a pure python question - do we need this `read()' here, i.e. if a file opened is delivered to exec, will it not being read anyway? Thanks Andreas -- https://code.launchpad.net/s-x-emacs-werkstatt/ http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/ From andreas.roehler at online.de Thu Oct 22 14:13:16 2009 From: andreas.roehler at online.de (Andreas Roehler) Date: Thu, 22 Oct 2009 14:13:16 +0200 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> Message-ID: <4AE04C5C.7000506@online.de> Rustom Mody wrote: > On Tue, Oct 20, 2009 at 1:59 PM, Andreas Roehler > > wrote: > > Rustom wrote: > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) # > > PYTHON-MODE\n" filename filename))) For me both of your variants are working, see output of checks below. uname -a && python --version && cat 2+4.py && cat exec-read.py && python exec-read.py && cat exec-compile-read.py && python exec-compile-read.py ==> Linux ... 2.6.22.19-0.2-default #1 SMP 2008-12-18 10:17:03 +0100 i686 athlon i386 GNU/Linux Python 2.5.1 #! /usr/bin/env python # -*- coding: utf-8 -*- print 2 + 4 ################## #! /usr/bin/env python # -*- coding: utf-8 -*- exec(open('2+4.py').read()) ###################### 6 #! /usr/bin/env python # -*- coding: utf-8 -*- exec(compile(open('2+4.py').read(), '2+4.py', 'exec')) ################# 6 ;;;;;;;;;;;;;;;;; BTW can you tell whats the us of `compile' here for you? Do you have some tests for python-mode.el? > What puzzles me still is a pure python question - > > do we need this `read()' here, i.e. if a file opened is > delivered to exec, will it not being read anyway? > > Thanks > > > See Guido's 2 to 3 doc > http://docs.python.org/dev/3.0/whatsnew/3.0.html#removed-syntax > says stream argument not taken > > Ah, thanks Andreas From andreas.roehler at online.de Thu Oct 22 17:02:31 2009 From: andreas.roehler at online.de (Andreas Roehler) Date: Thu, 22 Oct 2009 17:02:31 +0200 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> <4AE04C5C.7000506@online.de> Message-ID: <4AE07407.6050105@online.de> ... > > Rustom wrote: > > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) # > > > PYTHON-MODE\n" filename filename))) > > For me both of your variants are working, see output of checks below. > > You probably need to try on windows. > See > http://bugs.python.org/issue5524 Hmm, AFAIU the use of `compile' here on windows is to signal an error if the file contains "\r" chars? Right? > > uname -a && python --version && cat 2+4.py && cat exec-read.py && > python exec-read.py && > cat exec-compile-read.py && > python exec-compile-read.py > > ==> > > Linux ... 2.6.22.19-0.2-default #1 SMP 2008-12-18 10:17:03 +0100 > i686 athlon i386 GNU/Linux > Python 2.5.1 > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > print 2 + 4 > ################## > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > exec(open('2+4.py').read()) > ###################### > > 6 > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > exec(compile(open('2+4.py').read(), '2+4.py', 'exec')) > ################# > > 6 > > > ;;;;;;;;;;;;;;;;; > > BTW can you tell whats the us of `compile' here for you? > > See > http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0 > > > > Do you have some tests for python-mode.el? > > As in automated el/py etc? No > As in biological? ... If you may deliver a simple test case, how to call interactively it from inside emacs, it might be helpful - at least for me... :) Andreas > Heres yours truly :-) From andreas.roehler at online.de Thu Oct 22 21:20:17 2009 From: andreas.roehler at online.de (Andreas Roehler) Date: Thu, 22 Oct 2009 21:20:17 +0200 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> <4AE04C5C.7000506@online.de> <4AE07407.6050105@online.de> Message-ID: <4AE0B071.2020400@online.de> Rustom wrote: > On Thu, Oct 22, 2009 at 8:32 PM, Andreas Roehler > wrote: > >> ... >>> > Rustom wrote: >>> > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) >> # >>> > > PYTHON-MODE\n" filename filename))) >>> >>> For me both of your variants are working, see output of checks below. >>> >>> You probably need to try on windows. >>> See >>> http://bugs.python.org/issue5524 >> Hmm, AFAIU the use of `compile' here on windows is to signal an error if >> the file contains "\r" chars? >> Right? >> > The way I understood it the exec want Unix-only lineendings and compile > avoids the whole issue by supplying exec with a code object and not a > compilable text. > But I may be wrong Probably you are right - if the `\r'-error doesn't occur with `compile'. Think we should make a comment, saying "compile" here is introduced for this side-effect. > >>> Do you have some tests for python-mode.el? >>> >>> As in automated el/py etc? No >>> As in biological? ... >> If you may deliver a simple test case, how to call interactively it from >> inside emacs, >> it might be helpful - at least for me... :) >> > > Not sure what you are asking for. > Your emacs startup should contain something like > > (autoload 'py-shell "python-mode" "Python Inferior Mode." t) > (autoload 'python-mode "python-mode" "Python Mode." t) > (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) > (add-to-list 'interpreter-mode-alist '("python" . python-mode)) > > Also assuming that python-mode.el is in your path > > After that opening a file with .py extension should start in python mode >>From there C-c ! should start the python interpreter > After that (from the file buffer) C-c C-c should read the file into the > python interpreter buffer. > > But as I said I am not sure what you are asking for :-) > Sorry. Simply tried to catch the execution of your form with edebug. The ways I tried, it wasn't called. Thanks anyway. Andreas From rustompmody at gmail.com Thu Oct 22 07:16:14 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 22 Oct 2009 10:46:14 +0530 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: <4ADD74DC.1010806@online.de> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> Message-ID: On Tue, Oct 20, 2009 at 1:59 PM, Andreas Roehler wrote: > Rustom wrote: > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) # > > PYTHON-MODE\n" filename filename))) > What puzzles me still is a pure python question - > > do we need this `read()' here, i.e. if a file opened is > delivered to exec, will it not being read anyway? > > Thanks > > See Guido's 2 to 3 doc http://docs.python.org/dev/3.0/whatsnew/3.0.html#removed-syntax says stream argument not taken -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Thu Oct 22 16:25:29 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 22 Oct 2009 19:55:29 +0530 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: <4AE04C5C.7000506@online.de> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> <4AE04C5C.7000506@online.de> Message-ID: On Thu, Oct 22, 2009 at 5:43 PM, Andreas Roehler wrote: > Rustom Mody wrote: > > On Tue, Oct 20, 2009 at 1:59 PM, Andreas Roehler > > > wrote: > > > > Rustom wrote: > > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) # > > > PYTHON-MODE\n" filename filename))) > > For me both of your variants are working, see output of checks below. > > You probably need to try on windows. See http://bugs.python.org/issue5524 > uname -a && python --version && cat 2+4.py && cat exec-read.py && python > exec-read.py && > cat exec-compile-read.py && python > exec-compile-read.py > > ==> > > Linux ... 2.6.22.19-0.2-default #1 SMP 2008-12-18 10:17:03 +0100 i686 > athlon i386 GNU/Linux > Python 2.5.1 > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > print 2 + 4 > ################## > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > exec(open('2+4.py').read()) > ###################### > > 6 > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > exec(compile(open('2+4.py').read(), '2+4.py', 'exec')) > ################# > > 6 > > > ;;;;;;;;;;;;;;;;; > > BTW can you tell whats the us of `compile' here for you? > > See http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0 > Do you have some tests for python-mode.el? > As in automated el/py etc? No As in biological? ... Heres yours truly :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Thu Oct 22 18:03:08 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 22 Oct 2009 21:33:08 +0530 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: <4AE07407.6050105@online.de> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> <4AE04C5C.7000506@online.de> <4AE07407.6050105@online.de> Message-ID: On Thu, Oct 22, 2009 at 8:32 PM, Andreas Roehler wrote: > ... > > > Rustom wrote: > > > > (cmd (format "exec(compile(open('%s').read(), '%s', 'exec')) > # > > > > PYTHON-MODE\n" filename filename))) > > > > For me both of your variants are working, see output of checks below. > > > > You probably need to try on windows. > > See > > http://bugs.python.org/issue5524 > > Hmm, AFAIU the use of `compile' here on windows is to signal an error if > the file contains "\r" chars? > Right? > The way I understood it the exec want Unix-only lineendings and compile avoids the whole issue by supplying exec with a code object and not a compilable text. But I may be wrong > > > Do you have some tests for python-mode.el? > > > > As in automated el/py etc? No > > As in biological? ... > > If you may deliver a simple test case, how to call interactively it from > inside emacs, > it might be helpful - at least for me... :) > Not sure what you are asking for. Your emacs startup should contain something like (autoload 'py-shell "python-mode" "Python Inferior Mode." t) (autoload 'python-mode "python-mode" "Python Mode." t) (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)) Also assuming that python-mode.el is in your path After that opening a file with .py extension should start in python mode >From there C-c ! should start the python interpreter After that (from the file buffer) C-c C-c should read the file into the python interpreter buffer. But as I said I am not sure what you are asking for :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Oct 23 04:57:55 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 23 Oct 2009 08:27:55 +0530 Subject: [Python-mode] [Bug 450552] Re: python-mode breaks for python 3 In-Reply-To: <4AE0B071.2020400@online.de> References: <20091013174450.18764.96433.malonedeb@gandwana.canonical.com> <20091019130931.3875.15493.malone@gangotri.canonical.com> <4ADD74DC.1010806@online.de> <4AE04C5C.7000506@online.de> <4AE07407.6050105@online.de> <4AE0B071.2020400@online.de> Message-ID: On Fri, Oct 23, 2009 at 12:50 AM, Andreas Roehler wrote: > > Sorry. Simply tried to catch the execution of your form with edebug. > The ways I tried, it wasn't called. Ok -- Here goes 1. Take some trivial python file (say foo.py) in python-mode A single line x = 1 will do [I assume it opens with python-mode as major mode] 2. Set edebug to break function py-execute-file (in my case its line no 1358) 3. From foo.py do C-c ! (py-shell) to start python 4. Go back to foo.py buffer 5. Load using C-c C-c (py-execute-buffer) Why are 3 and 4 necessary? Dunno -- but they are at least in my case edebug should be at the breakpoint. Please tell me if this does not work. Rustom