python: improve support for modern python (CPython 3.2 and PyPy)
authorYaakov Selkowitz <yselkowitz@users.sourceforge.net>
Mon, 5 Nov 2012 17:45:15 +0000 (11:45 -0600)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 11 Nov 2012 00:26:43 +0000 (01:26 +0100)
This fixes automake bug#8847.

* m4/python.m4 (AM_PATH_PYTHON): Add python3.3 to
_AM_PYTHON_INTERPRETER_LIST.
* lib/py-compile: Fix compiled filenames for PEP-3147, currently
implemented in CPython 3.2 and newer.  Do not create '.pyo' files
for PyPy.

Copyright-paperwork-exempt: yes
Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/py-compile
m4/python.m4

index 6916903..14d0d12 100755 (executable)
@@ -116,7 +116,7 @@ else
 fi
 
 $PYTHON -c "
-import sys, os, py_compile
+import sys, os, py_compile, imp
 
 files = '''$files'''
 
@@ -129,12 +129,19 @@ for file in files.split():
            continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    py_compile.compile(filepath, filepath + 'c', path)
+    if hasattr(imp, 'get_tag'):
+        py_compile.compile(filepath, imp.cache_from_source(filepath), path)
+    else:
+        py_compile.compile(filepath, filepath + 'c', path)
 sys.stdout.write('\n')" || exit $?
 
 # this will fail for python < 1.5, but that doesn't matter ...
 $PYTHON -O -c "
-import sys, os, py_compile
+import sys, os, py_compile, imp
+
+# pypy does not use .pyo optimization
+if hasattr(sys, 'pypy_translation_info'):
+    sys.exit(0)
 
 files = '''$files'''
 sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
@@ -146,7 +153,10 @@ for file in files.split():
            continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    py_compile.compile(filepath, filepath + 'o', path)
+    if hasattr(imp, 'get_tag'):
+        py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
+    else:
+        py_compile.compile(filepath, filepath + 'o', path)
 sys.stdout.write('\n')" 2>/dev/null || :
 
 # Local Variables:
index a247818..50213a9 100644 (file)
@@ -37,7 +37,7 @@ AC_DEFUN([AM_PATH_PYTHON],
   dnl Find a Python interpreter.  Python versions prior to 2.0 are not
   dnl supported. (2.0 was released on October 16, 2000).
   m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
-[python python2 python3 python3.2 python3.1 python3.0 python2.7 dnl
+[python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl
  python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
 
   AC_ARG_VAR([PYTHON], [the Python interpreter])