all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#24954: [PATCH] Support Python 3
@ 2016-11-16 14:16 Syohei YOSHIDA
  2016-12-10 22:00 ` Justin Timmons
  0 siblings, 1 reply; 4+ messages in thread
From: Syohei YOSHIDA @ 2016-11-16 14:16 UTC (permalink / raw)
  To: 24954; +Cc: Syohei YOSHIDA

'print' statement was removed at Python 3. 'print' function should be
used instead of 'print' statement.
---
 modules/modhelp.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/modules/modhelp.py b/modules/modhelp.py
index 5d8f89b..d9a6312 100755
--- a/modules/modhelp.py
+++ b/modules/modhelp.py
@@ -45,31 +45,31 @@ def cmd_test(args):
 
     failed = []
     for m in mods:
-        print '[*] %s: ------- start -------' % m
-        print '[*] %s: running make' % m
+        print('[*] %s: ------- start -------' % m)
+        print('[*] %s: running make' % m)
         r = sp.call(make_cmd, cwd=m)
         if r != 0:
-            print '[E] %s: make failed' % m
+            print('[E] %s: make failed' % m)
             failed += [m]
             continue
 
-        print '[*] %s: running test' % m
+        print('[*] %s: running test' % m)
         testpath = os.path.join(m, 'test.el')
         if os.path.isfile(testpath):
             emacs_cmd = [EMACS, '-batch', '-L', '.', '-l', 'ert',
                          '-l', testpath, '-f', 'ert-run-tests-batch-and-exit']
-            print ' '.join(emacs_cmd)
+            print(' '.join(emacs_cmd))
             r = sp.call(emacs_cmd)
             if r != 0:
-                print '[E] %s: test failed' % m
+                print('[E] %s: test failed' % m)
                 failed += [m]
                 continue
         else:
-            print '[W] %s: no test to run' % m
+            print('[W] %s: no test to run' % m)
 
-    print '\n[*] %d/%d MODULES OK' % (len(mods)-len(failed), len(mods))
+    print('\n[*] %d/%d MODULES OK' % (len(mods)-len(failed), len(mods)))
     for m in failed:
-        print '\tfailed: %s' % m
+        print('\tfailed: %s' % m)
 
 def to_lisp_sym(sym):
     sym = re.sub('[_ ]', '-', sym)
@@ -81,7 +81,7 @@ def to_c_sym(sym):
 
 def cmd_init(args):
     if os.path.exists(args.module):
-        print "%s: file/dir '%s' already exists" % (__file__, args.module)
+        print("%s: file/dir '%s' already exists" % (__file__, args.module))
         return
 
     os.mkdir(args.module)
@@ -98,10 +98,10 @@ def cmd_init(args):
         if isinstance(path, string.Template):
             path = path.substitute(template_vars)
         path = os.path.join(args.module, path)
-        print "writing %s..." % path
+        print("writing %s..." % path)
         with open(path, "w+") as f:
             f.write(t.substitute(template_vars))
-    print "done! you can run %s test %s" % (__file__, args.module)
+    print("done! you can run %s test %s" % (__file__, args.module))
 
 
 def main():
-- 
2.9.3






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#24954: [PATCH] Support Python 3
  2016-11-16 14:16 bug#24954: [PATCH] Support Python 3 Syohei YOSHIDA
@ 2016-12-10 22:00 ` Justin Timmons
  2017-04-04  1:42   ` npostavs
  2017-12-03 15:50   ` Noam Postavsky
  0 siblings, 2 replies; 4+ messages in thread
From: Justin Timmons @ 2016-12-10 22:00 UTC (permalink / raw)
  To: Syohei YOSHIDA; +Cc: 24954

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]


DISCLAIMER: This is my first response to an emacs bug, so apologies in
advance for any mistakes =)

----------------------------------------------------------------------

I applied your patch and found another interoperability issue with
python3 - fixed in the attached patch file. argparse's subparsers have
had an issue from 3.3-3.5+ which doesn't cause a failure when a
subparser is omitted from the program's arguments. See the stackoverflow post here: http://stackoverflow.com/questions/18282403/argparse-with-required-subcommands#answer-18283730.

Running a quick `find` in the directory shows three total python files;
while modhelp was fairly trivial to be made python2/3 compatible, the
other two will require a little more work and some ugly boilerplate
without the use of something like the `six` library (eg. HTTPServer
being moved from BaseHTTPServer to http.server would split the imports
based on python version, among others).

  .../emacs/modules/modhelp.py
  .../emacs/test/manual/etags/pyt-src/server.py
  .../emacs/test/lisp/emacs-lisp/package-resources/package-test-server.py

This raises the question of whether or not these should be converted to be
python2/3 compatible, stay python2, or move to python3 altogether. I
wouldn't be able to answer that, but maybe one of the maintainers could
weigh in on it (I'm not sure who exactly, since there's not much in the maintainer list about python).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch file to convert modhelp.py to python3 --]
[-- Type: text/x-patch, Size: 2785 bytes --]

diff --git a/modules/modhelp.py b/modules/modhelp.py
index 445cb3b..64b90dd 100755
--- a/modules/modhelp.py
+++ b/modules/modhelp.py
@@ -45,31 +45,31 @@ def cmd_test(args):
 
     failed = []
     for m in mods:
-        print '[*] %s: ------- start -------' % m
-        print '[*] %s: running make' % m
+        print('[*] %s: ------- start -------' % m)
+        print('[*] %s: running make' % m)
         r = sp.call(make_cmd, cwd=m)
         if r != 0:
-            print '[E] %s: make failed' % m
+            print('[E] %s: make failed' % m)
             failed += [m]
             continue
 
-        print '[*] %s: running test' % m
+        print('[*] %s: running test' % m)
         testpath = os.path.join(m, 'test.el')
         if os.path.isfile(testpath):
             emacs_cmd = [EMACS, '-batch', '-L', '.', '-l', 'ert',
                          '-l', testpath, '-f', 'ert-run-tests-batch-and-exit']
-            print ' '.join(emacs_cmd)
+            print(' '.join(emacs_cmd))
             r = sp.call(emacs_cmd)
             if r != 0:
-                print '[E] %s: test failed' % m
+                print('[E] %s: test failed' % m)
                 failed += [m]
                 continue
         else:
-            print '[W] %s: no test to run' % m
+            print('[W] %s: no test to run' % m)
 
-    print '\n[*] %d/%d MODULES OK' % (len(mods)-len(failed), len(mods))
+    print('\n[*] %d/%d MODULES OK' % (len(mods)-len(failed), len(mods)))
     for m in failed:
-        print '\tfailed: %s' % m
+        print('\tfailed: %s' % m)
 
 def to_lisp_sym(sym):
     sym = re.sub('[_ ]', '-', sym)
@@ -81,7 +81,7 @@ def to_c_sym(sym):
 
 def cmd_init(args):
     if os.path.exists(args.module):
-        print "%s: file/dir '%s' already exists" % (__file__, args.module)
+        print("%s: file/dir '%s' already exists" % (__file__, args.module))
         return
 
     os.mkdir(args.module)
@@ -98,10 +98,10 @@ def cmd_init(args):
         if isinstance(path, string.Template):
             path = path.substitute(template_vars)
         path = os.path.join(args.module, path)
-        print "writing %s..." % path
+        print("writing %s..." % path)
         with open(path, "w+") as f:
             f.write(t.substitute(template_vars))
-    print "done! you can run %s test %s" % (__file__, args.module)
+    print("done! you can run %s test %s" % (__file__, args.module))
 
 
 def main():
@@ -109,7 +109,8 @@ def main():
     os.chdir(os.path.dirname(os.path.realpath(__file__)))
 
     mainp = argparse.ArgumentParser()
-    subp = mainp.add_subparsers()
+    subp = mainp.add_subparsers(dest='command')
+    subp.required = True
 
     testp = subp.add_parser('test', help='run tests')
     testp.add_argument('-f', '--force', action='store_true',

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#24954: [PATCH] Support Python 3
  2016-12-10 22:00 ` Justin Timmons
@ 2017-04-04  1:42   ` npostavs
  2017-12-03 15:50   ` Noam Postavsky
  1 sibling, 0 replies; 4+ messages in thread
From: npostavs @ 2017-04-04  1:42 UTC (permalink / raw)
  To: Justin Timmons; +Cc: 24954, Syohei YOSHIDA

Justin Timmons <justinmtimmons@gmail.com> writes:

> This raises the question of whether or not these should be converted to be
> python2/3 compatible, stay python2, or move to python3 altogether.

I think it's preferable to be python2/3 compatible, if that is not too
much trouble.  http://legacy.python.org/dev/peps/pep-0373/ says python
2.7 is still being supported until 2020, so we should support it at
least that long.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#24954: [PATCH] Support Python 3
  2016-12-10 22:00 ` Justin Timmons
  2017-04-04  1:42   ` npostavs
@ 2017-12-03 15:50   ` Noam Postavsky
  1 sibling, 0 replies; 4+ messages in thread
From: Noam Postavsky @ 2017-12-03 15:50 UTC (permalink / raw)
  To: Justin Timmons; +Cc: 24954, Syohei YOSHIDA

tags 24954 fixed
close 24954 26.1
quit

I pushed Syohei's patch to emacs-26 [1: de68f337e3].


Justin Timmons <justinmtimmons@gmail.com> writes:

> argparse's subparsers have
> had an issue from 3.3-3.5+ which doesn't cause a failure when a
> subparser is omitted from the program's arguments. See the
> stackoverflow post here:
> http://stackoverflow.com/questions/18282403/argparse-with-required-subcommands#answer-18283730.

>      mainp = argparse.ArgumentParser()
> -    subp = mainp.add_subparsers()
> +    subp = mainp.add_subparsers(dest='command')
> +    subp.required = True

I'm not going to apply this because it still produces a confusing error
message:

    modhelp.py: error: the following arguments are required: command

And if I read correctly from that link, the underlying bug should be
fixed in 3.7.

> This raises the question of whether or not these should be converted
> to be python2/3 compatible, stay python2, or move to python3
> altogether. I wouldn't be able to answer that, but maybe one of the
> maintainers could weigh in on it (I'm not sure who exactly, since
> there's not much in the maintainer list about python).

For me it actually raises the question of whether this "modhelper" thing
should be rewritten in elisp...

[1: de68f337e3]: 2017-12-03 10:04:18 -0500
  modhelp.py: Support Python 3 (Bug#24954)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=de68f337e36be7a40e5997ad6682770c42535c25





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-03 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-16 14:16 bug#24954: [PATCH] Support Python 3 Syohei YOSHIDA
2016-12-10 22:00 ` Justin Timmons
2017-04-04  1:42   ` npostavs
2017-12-03 15:50   ` Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.