[Jython-checkins] jython: Increment the API version (see #2158) & enable detailed error messages.

jeff.allen jython-checkins at python.org
Mon May 4 23:24:13 CEST 2015


https://hg.python.org/jython/rev/cb5bc04f17d1
changeset:   7703:cb5bc04f17d1
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Mon May 04 11:16:59 2015 +0100
summary:
  Increment the API version (see #2158) & enable detailed error messages.

Forces recompilation from source where old $py.class files may contain
incorrectly-generated import calls. When only a compiled file is found,
long-lost meaningful ImportError messages have been re-enabled.

files:
  src/org/python/core/imp.java |  17 +++++++++--------
  1 files changed, 9 insertions(+), 8 deletions(-)


diff --git a/src/org/python/core/imp.java b/src/org/python/core/imp.java
--- a/src/org/python/core/imp.java
+++ b/src/org/python/core/imp.java
@@ -28,7 +28,7 @@
 
     private static final String UNKNOWN_SOURCEFILE = "<unknown>";
 
-    private static final int APIVersion = 36;
+    private static final int APIVersion = 37;
 
     public static final int NO_MTIME = -1;
 
@@ -208,7 +208,7 @@
             String sourceName, String compiledName, long mtime, CodeImport source) {
         CodeData data = null;
         try {
-            data = readCodeData(name, fp, testing, mtime);
+            data = readCodeData(compiledName, fp, testing, mtime);
         } catch (IOException ioe) {
             if (!testing) {
                 throw Py.ImportError(ioe.getMessage() + "[name=" + name + ", source=" + sourceName
@@ -264,8 +264,8 @@
             if (testing) {
                 return null;
             } else {
-                throw Py.ImportError("invalid api version(" + api + " != " + APIVersion + ") in: "
-                        + name);
+                String fmt = "compiled unit contains version %d code (%d required): %.200s";
+                throw Py.ImportError(String.format(fmt, api, APIVersion, name));
             }
         }
         if (testing && mtime != NO_MTIME) {
@@ -639,9 +639,9 @@
                     Py.writeDebug(IMPORT_LOG, "trying precompiled " + compiledFile.getPath());
                     long classTime = compiledFile.lastModified();
                     if (classTime >= pyTime) {
-                        PyObject ret =
-                                createFromPyClass(modName, makeStream(compiledFile), true,
-                                        displaySourceName, displayCompiledName, pyTime);
+                        PyObject ret = createFromPyClass(modName, makeStream(compiledFile), //
+                                true, // OK to fail here as we have the source
+                                displaySourceName, displayCompiledName, pyTime);
                         if (ret != null) {
                             return ret;
                         }
@@ -656,7 +656,8 @@
             // If no source, try loading precompiled
             Py.writeDebug(IMPORT_LOG, "trying precompiled with no source " + compiledFile.getPath());
             if (compiledFile.isFile() && caseok(compiledFile, compiledName)) {
-                return createFromPyClass(modName, makeStream(compiledFile), true,
+                return createFromPyClass(modName, makeStream(compiledFile), //
+                        false, // throw ImportError here if this fails
                         displaySourceName, displayCompiledName, NO_MTIME, CodeImport.compiled_only);
             }
         } catch (SecurityException e) {

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list