Skip to content

Commit

Permalink
Relocate cache to working directory (fixes #2862)
Browse files Browse the repository at this point in the history
We no longer try to cache every user's JARs in the installation
directory, ineffective since fix of #2044. Behaviour for applications
that set an absolute location (or skip) is unchanged.
  • Loading branch information
jeff5 committed Feb 23, 2020
1 parent 0f36408 commit a19a5d2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bin
build
build2
cachedir
.jython_cache
dist
target

Expand Down
1 change: 1 addition & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ant.properties
build
build2
cachedir
.jython_cache
dist
publications
reports
Expand Down
5 changes: 1 addition & 4 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,7 @@ def tearDown(self):
os.chdir(self.cwd)
if self.pythonexe != sys.executable:
os.remove(self.pythonexe)
os.remove(self.file1_path)
os.remove(self.file2_path)
os.rmdir(self.cgi_dir)
os.rmdir(self.parent_dir)
test_support.rmtree(self.parent_dir)
finally:
BaseTestCase.tearDown(self)

Expand Down
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ https://github.com/jythontools/jython

Jython 2.7.2b4
Bugs fixed

- [ 2862 ] Jython fails on Linux for normal user when installed by root

Jython 2.7.2b3
Bugs fixed
Expand Down Expand Up @@ -122,6 +122,9 @@ Jython 2.7.2b1
- There is much improved support for locale, but as a backward-incompatible change, it is
provided as an opt-in. Define property python.locale.control=settable on the command line
or via the Jython registry, to enable. This may become the default in a later version.
- The default location of the Jython package cache has moved from the installation directory
to the current working directory and called ".jython_cache". Previously, Jython installed
system-wide either exposed the cache as world read-write (a security risk) or disabled it.

Jython 2.7.2a1
Bugs fixed
Expand Down
9 changes: 7 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ informix.jar = ../support/jdbc-4.10.12.jar
<property name="python.lib" value="${basedir}/lib-python/2.7" />
<property name="extlibs.dir" value="${basedir}/extlibs" />

<!-- Cache we need to clean (now it is not in dist.dir) -->
<property name="cache.dir" value="${basedir}/.jython_cache" />

<!-- Source specifically for test: -->
<property name="test.source.dir" value="${basedir}/tests/java" />
<property name="bugtests.dir" value="${basedir}/bugtests" />
Expand Down Expand Up @@ -413,12 +416,14 @@ informix.jar = ../support/jdbc-4.10.12.jar
<target name="clean" depends="common-dirs, clean-test"
description="Delete contents of working directories">
<delete includeemptydirs="true" failonerror="false">
<!-- the package cache (now it is not in dist.dir). -->
<fileset dir="${cache.dir}" includes="**/*" erroronmissingdir="false" />
<!-- all files and subdirectories of ${build.dir}, without ${build.dir} itself. -->
<fileset dir="${build.dir}" includes="**/*" defaultexcludes="false" />
<!-- all files and subdirectories of ${dist.dir}, without ${dist.dir} itself. -->
<fileset dir="${dist.dir}" includes="**/*" defaultexcludes="false" />
<!-- all files and subdirectories of ${pubs.dir}, without ${pubs.dir} itself. -->
<fileset dir="${pubs.dir}" includes="**/*" />
<fileset dir="${pubs.dir}" includes="**/*" erroronmissingdir="false" />
</delete>
</target>

Expand All @@ -428,7 +433,7 @@ informix.jar = ../support/jdbc-4.10.12.jar
<!-- all files and subdirectories of ${build.dir}, without ${build.dir} itself. -->
<fileset dir="${build.dir}" includes="**/*" excludes="gensrc/**" />
<!-- all files and subdirectories of ${dist.dir}, without ${dist.dir} itself. -->
<fileset dir="${dist.dir}" includes="**/*" excludes="cachedir/**, Lib/**" />
<fileset dir="${dist.dir}" includes="**/*" excludes="Lib/**" />
</delete>
</target>

Expand Down
6 changes: 4 additions & 2 deletions registry
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@

# Set the directory to use for caches (currently just package information)
# This directory should be writable by the user. If this is an absolute path it is used as given,
# otherwise it is interpreted relative to sys.prefix (typically the directory of this file).
python.cachedir = cachedir
# otherwise it is interpreted relative to the current working directory (at initialisation).
#python.cachedir = .jython_cache

# Setting this property to true disables the package scan for the cachedir.
# Please be aware that disabling this will break importing * from java packages
#python.cachedir.skip = false

# Properties to check for initializing and updating the package cache
# Values shown here are those hard-coded in Jython's cache manager.

# Treat JARs on the classpath and (up to Java 8) in the JRE as a source of Python packages.
#python.packages.paths = java.class.path, sun.boot.class.path # up to Java 8
#python.packages.paths = java.class.path # from Java 9
# Treat installed optional (Java) packages as source of Python packages (before Java 9)
#python.packages.directories = java.ext.dirs # up to Java 8
#python.packages.directories # undefined from Java 9


# DEPRECATED way to set the verbosity of messages output by Jython. If
# specified, "python.verbose" will set logging level for "org.python" when
# the runtime is initialised. It is better to use java.util.logging
Expand Down
6 changes: 4 additions & 2 deletions src/org/python/core/PySystemState.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PySystemState extends PyObject

private static final Logger logger = Logger.getLogger("org.python.core");

protected static final String CACHEDIR_DEFAULT_NAME = "cachedir";
private static final String CACHEDIR_DEFAULT_NAME = ".jython_cache";

public static final String JYTHON_JAR = "jython.jar";
public static final String JYTHON_DEV_JAR = "jython-dev.jar";
Expand Down Expand Up @@ -1270,9 +1270,11 @@ private static void initCacheDirectory(Properties props) {
}
cachedir = new File(props.getProperty(PYTHON_CACHEDIR, CACHEDIR_DEFAULT_NAME));
if (!cachedir.isAbsolute()) {
String prefixString = Py.fileSystemDecode(prefix);
String prefixString = props.getProperty("user.dir", "");
cachedir = new File(prefixString, cachedir.getPath());
cachedir = cachedir.getAbsoluteFile();
}
logger.log(Level.CONFIG, "cache at {0}", cachedir);
}

private static void initPackages(Properties props) {
Expand Down

0 comments on commit a19a5d2

Please sign in to comment.