# HG changeset patch # User Jeff Allen # Date 1537720015 -3600 # Sun Sep 23 17:26:55 2018 +0100 # Node ID 62363c91794386c3d7c7e3c75750c9876b3f344e # Parent fbe8e11c24c8587905d545c11786a8fb7393dc4d 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. diff -r fbe8e11c24c8 -r 62363c917943 Lib/test/test_java_integration.py --- a/Lib/test/test_java_integration.py Sun Sep 23 09:02:44 2018 +0100 +++ b/Lib/test/test_java_integration.py Sun Sep 23 17:26:55 2018 +0100 @@ -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 \n" "Rover barks 42 times$") diff -r fbe8e11c24c8 -r 62363c917943 NEWS --- a/NEWS Sun Sep 23 09:02:44 2018 +0100 +++ b/NEWS Sun Sep 23 17:26:55 2018 +0100 @@ -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 -r fbe8e11c24c8 -r 62363c917943 src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java Sun Sep 23 09:02:44 2018 +0100 +++ b/src/org/python/core/PySystemState.java Sun Sep 23 17:26:55 2018 +0100 @@ -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 -r fbe8e11c24c8 -r 62363c917943 src/org/python/util/jython.java --- a/src/org/python/util/jython.java Sun Sep 23 09:02:44 2018 +0100 +++ b/src/org/python/util/jython.java Sun Sep 23 17:26:55 2018 +0100 @@ -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.)