Skip to content

Commit f6be751

Browse files
committed
remove another instance of a cached path in a preinitialized context
1 parent 11e9354 commit f6be751

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public void patch(Env newEnv) {
258258
private void patchPackagePaths(String from, String to) {
259259
for (Object v : sysModules.getDictStorage().values()) {
260260
if (v instanceof PythonModule) {
261+
// Update module.__path__
261262
Object path = ((PythonModule) v).getAttribute(SpecialAttributeNames.__PATH__);
262263
if (path instanceof PList) {
263264
Object[] paths = ((PList) path).getSequenceStorage().getCopyOfInternalArray();
@@ -277,6 +278,18 @@ private void patchPackagePaths(String from, String to) {
277278
}
278279
((PythonModule) v).setAttribute(SpecialAttributeNames.__PATH__, core.factory().createList(paths));
279280
}
281+
282+
// Update module.__file__
283+
Object file = ((PythonModule) v).getAttribute(SpecialAttributeNames.__FILE__);
284+
String strFile = null;
285+
if (file instanceof PString) {
286+
strFile = ((PString) file).getValue();
287+
} else if (file instanceof String) {
288+
strFile = (String) file;
289+
}
290+
if (strFile != null) {
291+
((PythonModule) v).setAttribute(SpecialAttributeNames.__FILE__, strFile.replace(from, to));
292+
}
280293
}
281294
}
282295
}

mx.graalpython/mx_graalpython.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,14 @@ def graalpython_gate_runner(args, tasks):
394394
])
395395
if success not in out.data:
396396
mx.abort('Output from generated SVM image "' + svm_image + '" did not match success pattern:\n' + success)
397-
# Test that stdlib paths are not cached on e.g. encodings module
397+
# Test that stdlib paths are not cached on packages
398398
out = mx.OutputCapture()
399399
mx.run([svm_image, "-S", "--python.StdLibHome=/foobar", "-c", "import encodings; print(encodings.__path__)"], out=mx.TeeOutputCapture(out))
400+
if "/foobar" not in out.data:
401+
mx.abort('Output from generated SVM image "' + svm_image + '" did not have patched std lib path "/foobar", got:\n' + success)
402+
# Test that stdlib paths are not cached on modules
403+
out = mx.OutputCapture()
404+
mx.run([svm_image, "-S", "--python.StdLibHome=/foobar", "-c", "import encodings; print(encodings.__file__)"], out=mx.TeeOutputCapture(out))
400405
if "/foobar" not in out.data:
401406
mx.abort('Output from generated SVM image "' + svm_image + '" did not have patched std lib path "/foobar", got:\n' + success)
402407
# Finally, test that we can start even if the graalvm was moved

0 commit comments

Comments
 (0)