Title: site-packages support in standalone jar
Type: rfe Severity: major
Components: Core Versions: Jython 2.7
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: alex.gronholm, nonameentername, zyasoft
Priority: high Keywords: patch

Created on 2014-05-13.22:09:47 by nonameentername, last changed 2014-10-01.19:09:15 by zyasoft.

File name Uploaded Description Edit Remove
patch.diff nonameentername, 2014-05-20.19:55:25
msg8399 (view) Author: werner (nonameentername) Date: 2014-05-13.22:09:47
site-packages inside a jar does not get imported by jython.


import site
from org.python.util import jython
jar_location = jython().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
import site
import os.path
site.addsitedir(os.path.join(jar_location, 'Lib/site-packages'))
msg8400 (view) Author: Jim Baker (zyasoft) Date: 2014-05-13.22:11:35
Thanks for the workaround, this is very helpful for figuring out how to ensure this logic is always available in standalone mode.
msg8454 (view) Author: werner (nonameentername) Date: 2014-05-20.19:55:25
Add site-packages to the sys.path to allow finding site-packages inside a standalone jar
msg8532 (view) Author: Jim Baker (zyasoft) Date: 2014-05-22.01:07:12
More discussion in the duplicate bug #2149
msg8576 (view) Author: Jim Baker (zyasoft) Date: 2014-05-27.16:38:30
One idea I have here is that the built-in open function should be able to take a jar URL to the file in question and this can be resolved automagically against a jar that is on sys.path (including via __classpath__)

This change should then work transparently with normal search path resolution.

It should be fairly easy to test this idea out, given that we can directly take the result of getResourceAsStream and pass it to open.
msg9060 (view) Author: Alex Grönholm (alex.gronholm) Date: 2014-10-01.17:57:53
The workaround won't work in limited-permission use scenarios. "all-permissions" is required.
msg9061 (view) Author: Jim Baker (zyasoft) Date: 2014-10-01.17:59:51
Alex, even for using jar URLs? We will not be directly opening, but provide an alternative reader, via
msg9062 (view) Author: Alex Grönholm (alex.gronholm) Date: 2014-10-01.18:09:35
I hope this will shed some light to the issue:
msg9063 (view) Author: Jim Baker (zyasoft) Date: 2014-10-01.19:09:15
Alex, that's actually not a bad idea to simply extract the jar to a temporary file directory for these types of operations, vs using the resource API to access. This is very similar to what is done in egg support iirc.
Date User Action Args
2014-10-01 19:09:15zyasoftsetmessages: + msg9063
2014-10-01 18:09:36alex.gronholmsetmessages: + msg9062
2014-10-01 17:59:52zyasoftsetmessages: + msg9061
2014-10-01 17:57:53alex.gronholmsetnosy: + alex.gronholm
messages: + msg9060
2014-05-27 16:38:31zyasoftsetmessages: + msg8576
2014-05-22 01:07:12zyasoftsetmessages: + msg8532
2014-05-20 19:55:25nonameenternamesetfiles: + patch.diff
keywords: + patch
messages: + msg8454
2014-05-13 22:11:35zyasoftsetpriority: high
assignee: zyasoft
resolution: accepted
messages: + msg8400
nosy: + zyasoft
2014-05-13 22:09:47nonameenternamecreate