[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#24954: [PATCH] Support Python 3

From: Justin Timmons
Subject: bug#24954: [PATCH] Support Python 3
Date: Sat, 10 Dec 2016 17:00:57 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

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 

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).


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).

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]
-        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]
-            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))
@@ -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:
-    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():
     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',

reply via email to

[Prev in Thread] Current Thread [Next in Thread]