[Jython-checkins] jython: Ensure that the site module is imported when going through
jim.baker
jython-checkins at python.org
Fri Sep 27 20:46:58 CEST 2013
http://hg.python.org/jython/rev/7dac33227bb7
changeset: 7127:7dac33227bb7
user: Jim Baker <jim.baker at rackspace.com>
date: Fri Sep 27 12:46:53 2013 -0600
summary:
Ensure that the site module is imported when going through
Py#initProxy, if Options.importSite is true (default).
This step enables site-packages to be available before attempting to
import the module corresponding to the proxy. This code path is exercised
when directly using Python classes from Java, as seen in clamp.
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