[Jython-checkins] jython: Use python.path instead of JYTHONPATH #2706.

jeff.allen jython-checkins at python.org
Fri Oct 26 14:13:28 EDT 2018


https://hg.python.org/jython/rev/4057a7c55133
changeset:   8192:4057a7c55133
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Fri Oct 26 17:59:50 2018 +0100
summary:
  Use python.path instead of JYTHONPATH #2706.

The change restricts the influence of JYTHONPATH to org.python.util.jython (the
jython command), and makes it subject to the -E option (ignore environment).
JYTHONPATH will no longer affect sys.path in applications that create their own
interpreter. The system/registry property python.path continues to have that
role.

files:
  Lib/test/test_java_integration.py      |  11 ++++-------
  NEWS                                   |   6 ++++++
  src/org/python/core/PySystemState.java |   9 ---------
  src/org/python/util/jython.java        |   4 ++++
  4 files changed, 14 insertions(+), 16 deletions(-)


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
@@ -728,14 +728,12 @@
             jars = find_jython_jars()
             jars.append(proxies_jar_path)
             classpath = os.pathsep.join(jars)
-            env = dict(os.environ)
-            env.update(JYTHONPATH=os.path.dirname(__file__))
             cmd = [os.path.join(System.getProperty("java.home"), "bin", "java"),
+                   "-Dpython.path=" + os.path.dirname(__file__),
                     "-classpath", classpath,
                     "javatests.ProxyDeserialization",
                     cat_path]
-            self.assertEqual(subprocess.check_output(cmd, env=env, universal_newlines=True),
-                             "meow\n")
+            self.assertEqual(subprocess.check_output(cmd, universal_newlines=True), "meow\n")
         finally:
             org.python.core.Options.proxyDebugDirectory = old_proxy_debug_dir
             shutil.rmtree(tempdir)
@@ -792,11 +790,10 @@
             # the proxy
             classpath += os.pathsep + tempdir
             cmd = [os.path.join(System.getProperty("java.home"), "bin", "java"),
+                   "-Dpython.path=" + os.path.dirname(__file__),
                    "-classpath", classpath, "BarkTheDog"]
-            env = dict(os.environ)
-            env.update(JYTHONPATH=os.path.dirname(__file__))
             self.assertRegexpMatches(
-                subprocess.check_output(cmd, env=env, universal_newlines=True,
+                subprocess.check_output(cmd, universal_newlines=True,
                                         stderr=subprocess.STDOUT),
                 r"^Class defined on CLASSPATH <type 'org.python.test.bark.Dog'>\n"
                                         "Rover barks 42 times$")
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
 
 Development tip
   Bugs fixed
+    - [ 2706 ] Use python.path instead of JYTHONPATH
     - [ 2410 ] Regression in PySystemStateTest (leading slash)
     - [ 2639 ] Incorrect result when using != comparison against Java {List, Set, Map}
     - [ 2672 ] Integer formatting emits two minus signs with -2^31
@@ -26,6 +27,11 @@
       treatment of the -i option. This simplifies support, and may also make it unnecessary for
       users to work around differences from CPython.
     - python.startup registry property (and JYTHONSTARTUP environment variable) added.
+    - Only the Jython command (class org.python.util.jython) now reads the environment variable
+      JYTHONPATH, not the core runtime, abd it respects the -E option (ignore environment). This
+      change is for consistency with CPython and with our handling of other environment variables.
+      A pure Java application that creates its own interpreter may use the system or registry
+      key "python.path" to add to sys.path, as documented.
 
 Jython 2.7.2a1
   Bugs fixed
diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java
--- a/src/org/python/core/PySystemState.java
+++ b/src/org/python/core/PySystemState.java
@@ -955,15 +955,6 @@
         if (exec_prefix != null) {
             PySystemState.exec_prefix = Py.fileSystemEncode(exec_prefix);
         }
-        try {
-            // XXX: Respect or ignore Options.ignore_environment?
-            String jythonpath = System.getenv("JYTHONPATH");
-            if (jythonpath != null) {
-                registry.setProperty("python.path", jythonpath);
-            }
-        } catch (SecurityException e) {
-            // Continue
-        }
 
         // Now the post properties (possibly set by custom JythonInitializer).
         registry.putAll(postProperties);
diff --git a/src/org/python/util/jython.java b/src/org/python/util/jython.java
--- a/src/org/python/util/jython.java
+++ b/src/org/python/util/jython.java
@@ -608,6 +608,10 @@
      * @param registry to be (possibly) updated
      */
     private static void addDefaultsFromEnvironment(Properties registry) {
+
+        // Pick up the path from the environment
+        addDefault(registry, "python.path", getenv("JYTHONPATH"));
+
         // Runs at the start of each (wholly) interactive session.
         addDefault(registry, "python.startup", getenv("JYTHONSTARTUP"));
         // Go interactive after script. (PYTHONINSPECT because Python scripts may set it.)

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


More information about the Jython-checkins mailing list