[Jython-checkins] jython (merge default -> default): Merge buffer development

jeff.allen jython-checkins at python.org
Fri Sep 27 21:17:21 CEST 2013


http://hg.python.org/jython/rev/f731a595b90a
changeset:   7130:f731a595b90a
parent:      7129:2751805d22a5
parent:      7127:7dac33227bb7
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Fri Sep 27 20:15:57 2013 +0100
summary:
  Merge buffer development

files:
  Lib/test/bark.py                  |   4 ++++
  Lib/test/test_java_integration.py |  17 +++++++++++------
  src/org/python/core/Py.java       |   6 ++++++
  3 files changed, 21 insertions(+), 6 deletions(-)


diff --git a/Lib/test/bark.py b/Lib/test/bark.py
--- a/Lib/test/bark.py
+++ b/Lib/test/bark.py
@@ -1,5 +1,6 @@
 from __future__ import print_function
 
+import sys
 from java.io import Serializable
 from java.util.concurrent import Callable
 
@@ -25,6 +26,9 @@
     def call(self):
         # Using print forces use of PySystemState and shows it's initialized
         print("%s barks %s times" % (self.name, self.number))
+        # Verify that site has been imported and therefore
+        # site-packages and distutils/setuptools goodness is available
+        return "site" in sys.modules
 
     def __eq__(self, other):
         return self.name == other.name and self.number == other.number
diff --git a/Lib/test/test_java_integration.py b/Lib/test/test_java_integration.py
--- a/Lib/test/test_java_integration.py
+++ b/Lib/test/test_java_integration.py
@@ -668,7 +668,7 @@
         tempdir = tempfile.mkdtemp()
         try:
             SerializableProxies.serialized_path = tempdir
-            import bark #importlib.import_module("bark")
+            import bark
             dog = bark.Dog()
             self.assertEqual(dog.whoami(), "Rover")
             self.assertEqual(dog.serialVersionUID, 1)
@@ -686,7 +686,10 @@
     public static void main(String[] args) {
         Dog dog = new Dog();
         try {
-            dog.call();
+            Boolean b = (Boolean)(dog.call());
+            if (!b) {
+                throw new RuntimeException("Expected site module to be imported");
+            }
         }
         catch(Exception e) {
             System.err.println(e);
@@ -711,10 +714,12 @@
                    "-classpath", classpath, "BarkTheDog"]
             env = dict(os.environ)
             env.update(JYTHONPATH=os.path.normpath(os.path.join(__file__, "..")))
-            self.assertEqual(
-                subprocess.check_output(cmd, env=env, universal_newlines=True),
-                    "Class defined on CLASSPATH <type 'org.python.test.bark.Dog'>\n"
-                    "Rover barks 42 times\n")
+            self.assertRegexpMatches(
+                subprocess.check_output(cmd, env=env, universal_newlines=True,
+                                        stderr=subprocess.STDOUT),
+                r"^\*sys-package-mgr\*: processing new jar, '.+?/proxies.jar'\n"
+                 "Class defined on CLASSPATH <type 'org.python.test.bark.Dog'>\n"
+                 "Rover barks 42 times\n$".format(tempdir))
         finally:
             pass
             # print "Will not remove", tempdir
diff --git a/src/org/python/core/Py.java b/src/org/python/core/Py.java
--- a/src/org/python/core/Py.java
+++ b/src/org/python/core/Py.java
@@ -950,6 +950,12 @@
             return;
         }
 
+        if (Options.importSite) {
+            // Ensure site-packages are available before attempting to import module.
+            // This step enables supporting modern Python apps when using proxies
+            // directly from Java (eg through clamp).
+            imp.load("site");
+        }
         PyObject mod = imp.importName(module.intern(), false);
         PyType pyc = (PyType)mod.__getattr__(pyclass.intern());
 

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


More information about the Jython-checkins mailing list