Skip to content

Commit 2120618

Browse files
timfelfangerer
authored andcommitted
Merge remote-tracking branch 'origin/master' into topic/GR-13481
2 parents 5c51bbe + e9902f6 commit 2120618

File tree

32 files changed

+612
-400
lines changed

32 files changed

+612
-400
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,15 @@ protected void launch(Builder contextBuilder) {
394394
unbufferedIO = unbufferedIO || System.getenv("PYTHONUNBUFFERED") != null;
395395
}
396396

397-
// The unlikely separator is used because options need to be strings. See
398-
// PythonOptions.getExecutableList()
399-
contextBuilder.option("python.ExecutableList", String.join("🏆", getExecutableList()));
400-
setContextOptionIfUnset(contextBuilder, "python.Executable", getExecutable());
397+
String executable = getContextOptionIfSetViaCommandLine("python.Executable");
398+
if (executable != null) {
399+
contextBuilder.option("python.ExecutableList", executable);
400+
} else {
401+
contextBuilder.option("python.Executable", getExecutable());
402+
// The unlikely separator is used because options need to be
403+
// strings. See PythonOptions.getExecutableList()
404+
contextBuilder.option("python.ExecutableList", String.join("🏆", getExecutableList()));
405+
}
401406

402407
// setting this to make sure our TopLevelExceptionHandler calls the excepthook
403408
// to print Python exceptions
@@ -471,16 +476,21 @@ protected void launch(Builder contextBuilder) {
471476
System.exit(rc);
472477
}
473478

474-
private void setContextOptionIfUnset(Builder contextBuilder, String key, String value) {
479+
private String getContextOptionIfSetViaCommandLine(String key) {
475480
if (System.getProperty("polyglot." + key) != null) {
476-
return;
481+
return System.getProperty("polyglot." + key);
477482
}
478483
for (String f : givenArguments) {
479484
if (f.startsWith("--" + key)) {
480-
return;
485+
String[] splits = f.split("=", 2);
486+
if (splits.length > 1) {
487+
return splits[1];
488+
} else {
489+
return "true";
490+
}
481491
}
482492
}
483-
contextBuilder.option(key, value);
493+
return null;
484494
}
485495

486496
private static void printFileNotFoundException(NoSuchFileException e) {

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ private static Source createSource(String resourceName) throws IOException {
318318
int slashIndex = resourceName.lastIndexOf('/');
319319
String scriptName = slashIndex >= 0 ? resourceName.substring(slashIndex + 1) : resourceName;
320320
Reader in = new InputStreamReader(PythonProvider.class.getResourceAsStream(resourceName), "UTF-8");
321-
return Source.newBuilder(ID, in, scriptName).build();
321+
try {
322+
return Source.newBuilder(ID, in, scriptName).build();
323+
} finally {
324+
if (in != null) {
325+
in.close();
326+
}
327+
}
322328
}
323329

324330
private abstract static class PResultVerifier implements ResultVerifier {

graalpython/com.oracle.graal.python.test/src/tests/test_zipimport.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -24,9 +24,12 @@ def get_file():
2424
"""
2525

2626
ZIP_FILE_NAME = 'testzipfile.zip'
27+
EGG_FILE_NAME = 'testeggfile.egg'
2728
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
2829
ZIP_PATH = os.path.join(DIR_PATH, ZIP_FILE_NAME)
2930
ZIP_ABS_PATH = os.path.abspath(ZIP_PATH);
31+
EGG_PATH = os.path.join(DIR_PATH, EGG_FILE_NAME)
32+
EGG_ABS_PATH = os.path.abspath(EGG_PATH);
3033

3134
class ZipImportBaseTestCase(unittest.TestCase):
3235

@@ -176,3 +179,26 @@ def test_module_import(self):
176179
self.assertTrue (m.get_file() == ZIP_ABS_PATH + "/MyTestModule.py")
177180
p = importlib.import_module("packageA.moduleC")
178181
self.assertTrue (p.get_file() == ZIP_ABS_PATH + "/packageA/moduleC.py")
182+
183+
class BasicEggImportTests(ZipImportBaseTestCase):
184+
185+
def setUp(self):
186+
ZipImportBaseTestCase.setUp(self)
187+
self.z = zipimport.zipimporter(EGG_PATH)
188+
189+
def test_zipimporter_egg(self):
190+
self.assertTrue(self.z.prefix == "")
191+
self.assertTrue(self.z.archive == EGG_ABS_PATH)
192+
self.assertTrue(type(self.z._files) is dict)
193+
self.assertTrue(self.z._files["data.bin"] is not None)
194+
self.assertTrue(self.z._files["read.me"] is not None)
195+
196+
def test_egg_get_data(self):
197+
data = self.z.get_data("data.bin")
198+
self.assertTrue(type(data) is bytes)
199+
self.assertEqual(bytes(b'ahojPK\003\004ahoj'), data)
200+
201+
def test_egg_get_readme(self):
202+
data = self.z.get_data("read.me")
203+
self.assertTrue(type(data) is bytes)
204+
self.assertEqual(bytes(b'Pokus\n'), data)
Binary file not shown.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ private void ensureHomeInOptions(Env env) {
218218
"\n\tSysPrefix: {1}" +
219219
"\n\tSysBasePrefix: {2}" +
220220
"\n\tCoreHome: {3}" +
221-
"\n\tStdLibHome: {4}", home.getPath(), sysPrefix, basePrefix, coreHome, stdLibHome)));
221+
"\n\tStdLibHome: {4}" +
222+
"\n\tExecutable: {5}", home.getPath(), sysPrefix, basePrefix, coreHome, stdLibHome, env.getOptions().get(PythonOptions.Executable))));
222223
}
223224
}
224225

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ private void addBuiltinsTo(PythonObject obj, PythonBuiltins builtinsForObj) {
600600

601601
@TruffleBoundary
602602
private Source getSource(String basename, String prefix) {
603-
String suffix = FILE_SEPARATOR + basename + ".py";
604603
PythonContext ctxt = getContext();
605604
Env env = ctxt.getEnv();
605+
String suffix = env.getFileNameSeparator() + basename + ".py";
606606
TruffleFile file = env.getTruffleFile(prefix + suffix);
607607
try {
608608
if (file.exists()) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ private Object typeMetaclass(String name, PTuple bases, PDict namespace, PythonA
19041904
boolean addDict = false;
19051905
if (slots == null) {
19061906
// takes care of checking if we may_add_dict and adds it if needed
1907-
addDict = addDictIfNative(pythonClass);
1907+
addDictIfNative(pythonClass);
19081908
// TODO: tfel - also deal with weaklistoffset
19091909
} else {
19101910
// have slots

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void ensureCapiWasLoaded() {
227227
if (!ctxt.capiWasLoaded()) {
228228
Env env = ctxt.getEnv();
229229
CompilerDirectives.transferToInterpreterAndInvalidate();
230-
TruffleFile capiFile = env.getTruffleFile(PythonCore.getCoreHome(env) + PythonCore.FILE_SEPARATOR + "capi.bc");
230+
TruffleFile capiFile = env.getTruffleFile(PythonCore.getCoreHome(env) + env.getFileNameSeparator() + "capi.bc");
231231
Object capi = null;
232232
try {
233233
SourceBuilder capiSrcBuilder = Source.newBuilder(LLVM_LANGUAGE, capiFile);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import java.util.Set;
7474
import java.util.concurrent.TimeUnit;
7575

76+
import com.oracle.graal.python.PythonLanguage;
7677
import com.oracle.graal.python.builtins.Builtin;
7778
import com.oracle.graal.python.builtins.CoreFunctions;
7879
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -1343,6 +1344,7 @@ int system(String cmd) {
13431344
if (!context.isExecutableAccessAllowed()) {
13441345
return -1;
13451346
}
1347+
PythonLanguage.getLogger().fine(() -> "os.system: " + cmd);
13461348
String[] command = new String[]{shell[0], shell[1], cmd};
13471349
Env env = context.getEnv();
13481350
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
import java.util.List;
5252
import java.util.Map;
5353

54-
import org.graalvm.nativeimage.ImageInfo;
55-
54+
import com.oracle.graal.python.PythonLanguage;
5655
import com.oracle.graal.python.builtins.Builtin;
5756
import com.oracle.graal.python.builtins.CoreFunctions;
5857
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -77,6 +76,8 @@
7776
import com.oracle.truffle.api.dsl.NodeFactory;
7877
import com.oracle.truffle.api.dsl.Specialization;
7978

79+
import org.graalvm.nativeimage.ImageInfo;
80+
8081
@CoreFunctions(defineModule = "_posixsubprocess")
8182
public class PosixSubprocessModuleBuiltins extends PythonBuiltins {
8283
@Override
@@ -129,6 +130,7 @@ synchronized int forkExec(PList args, @SuppressWarnings("unused") PList execList
129130
}
130131
}
131132

133+
PythonLanguage.getLogger().fine(() -> "_posixsubprocess.fork_exec: " + String.join(" ", argStrings));
132134
ProcessBuilder pb = new ProcessBuilder(argStrings);
133135
if (p2cread != -1 && p2cwrite != -1) {
134136
pb.redirectInput(Redirect.PIPE);

0 commit comments

Comments
 (0)