Skip to content

Commit d8aa2ce

Browse files
committed
[GR-36700] Python language library.
PullRequest: graalpython/2263
2 parents 7e5e84c + de91941 commit d8aa2ce

File tree

9 files changed

+63
-40
lines changed

9 files changed

+63
-40
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "2a6018d949661319d714f343bc2b7f0f972b4a26" }
1+
{ "overlay": "bbd123566faf600786d8ea6dc6a16639f9f97bce" }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
331331
}
332332
}
333333

334+
if (!ImageInfo.inImageCode()) {
335+
for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
336+
if (arg.equals("-ea")) {
337+
addRelaunchArg("--vm.ea");
338+
break;
339+
}
340+
}
341+
}
342+
334343
// According to CPython if no arguments are given, they contain an empty string.
335344
if (programArgs.isEmpty()) {
336345
programArgs.add("");

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/ProfileTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
package com.oracle.graal.python.test.runtime;
4242

4343
import org.junit.Before;
44-
import org.junit.Test;
4544

4645
import com.oracle.graal.python.test.PythonTests;
46+
import org.junit.Ignore;
4747

4848
import java.io.ByteArrayOutputStream;
4949
import java.io.PrintStream;
@@ -57,7 +57,7 @@ public void ensureBytecode() {
5757
PythonTests.skipOnLegacyASTInterpreter();
5858
}
5959

60-
@Test
60+
@Ignore("due to GR-40923")
6161
public void profileYield() {
6262
String source = "import sys\n" +
6363
"def f(frame, event, arg): print(frame, event, arg)\n" +
@@ -72,7 +72,7 @@ public void profileYield() {
7272
"<module>> return None\n", source);
7373
}
7474

75-
@Test
75+
@Ignore("due to GR-40923")
7676
public void profileException() {
7777
String source = "import sys\n" +
7878
"def f(frame, event, arg): print(frame, event, arg)\n" +

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -126,3 +126,13 @@ def test_kill(self):
126126
finally:
127127
p.kill()
128128
p.wait()
129+
130+
def test_java_asserts(self):
131+
import sys
132+
if sys.implementation.name == "graalpy":
133+
import subprocess, __graalpython__
134+
if __graalpython__.java_assert():
135+
result = subprocess.run([sys.executable, "-c", "import __graalpython__; __graalpython__.java_assert()"])
136+
else:
137+
result = subprocess.run([sys.executable, "-c", "import __graalpython__; not __graalpython__.java_assert()"])
138+
assert result.returncode == 0

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,15 @@ TruffleString doit(VirtualFrame frame,
712712
return fromJavaStringNode.execute(tempFile.getPath(), TS_ENCODING);
713713
}
714714
}
715+
716+
@Builtin(name = "java_assert", minNumOfPositionalArgs = 0)
717+
@GenerateNodeFactory
718+
abstract static class JavaAssertNode extends PythonBuiltinNode {
719+
@Specialization
720+
Object doit() {
721+
boolean assertOn = false;
722+
assert assertOn = true;
723+
return assertOn;
724+
}
725+
}
715726
}

mx.graalpython/graalpython-launcher

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
DISABLE_INSTALLABLES=true
22
DYNAMIC_IMPORTS=/vm,/substratevm
3-
NATIVE_IMAGES=graalpy
3+
NATIVE_IMAGES=lib:pythonvm
44
NO_LICENSES=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
DISABLE_INSTALLABLES=true
22
DYNAMIC_IMPORTS=/substratevm,/graalpython-enterprise
3-
NATIVE_IMAGES=graalpy
3+
NATIVE_IMAGES=lib:pythonvm
44
NO_LICENSES=true

mx.graalpython/mx_graalpython.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def run_cpython_test(args):
311311
env = os.environ.copy()
312312
delete_bad_env_keys(env)
313313
with _dev_pythonhome_context():
314-
mx.run([python_gvm_with_assertions()] + interp_args + [
314+
mx.run([python_gvm()] + ['--vm.ea'] + interp_args + [
315315
os.path.join(SUITE.dir, "graalpython/com.oracle.graal.python.test/src/tests/run_cpython_test.py"),
316316
] + test_args + testfiles, env=env)
317317

@@ -342,7 +342,9 @@ def retag_unittests(args):
342342
'graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py',
343343
'--retag'
344344
]
345-
vm = python_svm() if not parsed_args.jvm else python_gvm_with_assertions()
345+
vm = python_svm() if not parsed_args.jvm else python_gvm()
346+
if parsed_args.jvm:
347+
args += ['-ea']
346348
mx.run([vm] + args + remaining_args, env=env)
347349
if parsed_args.upload_results_to:
348350
with tempfile.TemporaryDirectory(prefix='graalpython-retagger-') as d:
@@ -590,18 +592,6 @@ def python_enterprise_gvm(_=None):
590592
mx.log(launcher)
591593
return launcher
592594

593-
def python_gvm_with_assertions():
594-
launcher = python_gvm()
595-
patch_batch_launcher(launcher, '-ea')
596-
return launcher
597-
598-
599-
def python_managed_gvm_with_assertions():
600-
launcher = python_managed_gvm()
601-
patch_batch_launcher(launcher, '-ea')
602-
return launcher
603-
604-
605595
def python_svm(_=None):
606596
home = _graalvm_home(envfile="graalpython-launcher")
607597
launcher = _join_bin(home, "graalpy")
@@ -695,7 +685,7 @@ def is_included(path):
695685

696686

697687
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=False, exclude=None, env=None,
698-
use_pytest=False, cwd=None, lock=None, out=None, err=None, nonZeroIsFatal=True):
688+
use_pytest=False, cwd=None, lock=None, out=None, err=None, nonZeroIsFatal=True, javaAsserts=False):
699689
if lock:
700690
lock.acquire()
701691
# ensure that the test distribution is up-to-date
@@ -759,6 +749,9 @@ def graalvm_vm_arg(java_arg):
759749
mx.run([python_binary, "--jvm", agent_args] + args + [testfile],
760750
nonZeroIsFatal=nonZeroIsFatal, env=env, cwd=cwd, out=out, err=err)
761751
else:
752+
if javaAsserts:
753+
args += ['-ea']
754+
762755
args += testfiles
763756
mx.logv(" ".join([python_binary] + args))
764757
if lock:
@@ -838,7 +831,7 @@ def run(self):
838831
mx.abort("At least one HPy testing thread failed.")
839832

840833

841-
def run_tagged_unittests(python_binary, env=None, cwd=None):
834+
def run_tagged_unittests(python_binary, env=None, cwd=None, javaAsserts=False):
842835
if env is None:
843836
env = os.environ
844837
sub_env = env.copy()
@@ -852,7 +845,8 @@ def run_tagged_unittests(python_binary, env=None, cwd=None):
852845
args=["-v"],
853846
paths=["test_tagged_unittests.py"],
854847
env=sub_env,
855-
cwd=cwd
848+
cwd=cwd,
849+
javaAsserts=javaAsserts
856850
)
857851

858852

@@ -877,19 +871,19 @@ def graalpython_gate_runner(args, tasks):
877871
test_args = [exe, _graalpytest_driver(), "-v", _graalpytest_root()]
878872
mx.run(test_args, nonZeroIsFatal=True, env=env)
879873
mx.run(["env"])
880-
run_python_unittests(python_gvm_with_assertions())
874+
run_python_unittests(python_gvm(), javaAsserts=True)
881875

882876
with Task('GraalPython sandboxed tests', tasks, tags=[GraalPythonTags.unittest_sandboxed]) as task:
883877
if task:
884-
run_python_unittests(python_managed_gvm_with_assertions())
878+
run_python_unittests(python_managed_gvm(), javaAsserts=True)
885879

886880
with Task('GraalPython multi-context unittests', tasks, tags=[GraalPythonTags.unittest_multi]) as task:
887881
if task:
888-
run_python_unittests(python_gvm_with_assertions(), args=["-multi-context"])
882+
run_python_unittests(python_gvm(), args=["-multi-context"], javaAsserts=True)
889883

890884
with Task('GraalPython Jython emulation tests', tasks, tags=[GraalPythonTags.unittest_jython]) as task:
891885
if task:
892-
run_python_unittests(python_gvm_with_assertions(), args=["--python.EmulateJython"], paths=["test_interop.py"])
886+
run_python_unittests(python_gvm(), args=["--python.EmulateJython"], paths=["test_interop.py"], javaAsserts=True)
893887

894888
with Task('GraalPython HPy tests', tasks, tags=[GraalPythonTags.unittest_hpy]) as task:
895889
if task:
@@ -901,8 +895,8 @@ def graalpython_gate_runner(args, tasks):
901895

902896
with Task('GraalPython posix module tests', tasks, tags=[GraalPythonTags.unittest_posix]) as task:
903897
if task:
904-
run_python_unittests(python_gvm_with_assertions(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"])
905-
run_python_unittests(python_gvm_with_assertions(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"])
898+
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True)
899+
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True)
906900

907901
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
908902
if task:
@@ -1652,10 +1646,9 @@ def verify_ci(dest_suite, common_ci_dir="ci_common", args=None, ext=('.jsonnet',
16521646
'graalpython:GRAALPYTHON_GRAALVM_SUPPORT',
16531647
'graalpython:GRAALPYTHON_GRAALVM_DOCS',
16541648
],
1655-
launcher_configs=[
1656-
mx_sdk.LanguageLauncherConfig(
1657-
destination='bin/<exe:graalpy>',
1658-
links=['bin/python', 'bin/python3'],
1649+
library_configs=[
1650+
mx_sdk.LanguageLibraryConfig(
1651+
launchers=['bin/<exe:graalpy>', 'bin/<exe:python>', 'bin/<exe:python3>'],
16591652
jar_distributions=['graalpython:GRAALPYTHON-LAUNCHER'],
16601653
main_class=GRAALPYTHON_MAIN_CLASS,
16611654
build_args=[
@@ -1814,7 +1807,7 @@ def python_coverage(args):
18141807
'coverage-upload',
18151808
])
18161809
if args.truffle:
1817-
executable = python_gvm_with_assertions()
1810+
executable = python_gvm()
18181811
variants = [
18191812
{"args": []},
18201813
{"args": ["--python.EmulateJython"], "paths": ["test_interop.py"]},
@@ -1844,9 +1837,9 @@ def python_coverage(args):
18441837
env['GRAAL_PYTHON_ARGS'] = " ".join(extra_args)
18451838
env['ENABLE_THREADED_GRAALPYTEST'] = "false"
18461839
if kwds.pop("tagged", False):
1847-
run_tagged_unittests(executable, env=env)
1840+
run_tagged_unittests(executable, env=env, javaAsserts=True)
18481841
else:
1849-
run_python_unittests(executable, env=env, **kwds)
1842+
run_python_unittests(executable, env=env, javaAsserts=True, **kwds)
18501843

18511844
# generate a synthetic lcov file that includes all sources with 0
18521845
# coverage. this is to ensure all sources actuall show up - otherwise,

mx.graalpython/suite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@
4444
},
4545
{
4646
"name": "tools",
47-
"version": "fd894b8a9d8a5254e35df726c9ab718e37e29525",
47+
"version": "9a0570863be7d236519bceda4b05ee3e00a6c384",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
],
5252
},
5353
{
5454
"name": "sulong",
55-
"version": "fd894b8a9d8a5254e35df726c9ab718e37e29525",
55+
"version": "9a0570863be7d236519bceda4b05ee3e00a6c384",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},
5959
]
6060
},
6161
{
6262
"name": "regex",
63-
"version": "fd894b8a9d8a5254e35df726c9ab718e37e29525",
63+
"version": "9a0570863be7d236519bceda4b05ee3e00a6c384",
6464
"subdir": True,
6565
"urls": [
6666
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)