Skip to content

Commit d2a7554

Browse files
committed
[GR-34606] Fixes for jinja2
PullRequest: graalpython/2112
2 parents ea37718 + 2190d87 commit d2a7554

File tree

6 files changed

+51
-44
lines changed

6 files changed

+51
-44
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -621,7 +621,7 @@ protected void launch(Builder contextBuilder) {
621621
}
622622
consoleHandler.setContext(context);
623623

624-
if (commandString != null || inputFile != null) {
624+
if (commandString != null || inputFile != null || !stdinIsInteractive) {
625625
try {
626626
evalNonInteractive(context, consoleHandler);
627627
rc = 0;
@@ -722,8 +722,7 @@ private void evalNonInteractive(Context context, ConsoleHandler consoleHandler)
722722
if (commandString != null) {
723723
src = Source.newBuilder(getLanguageId(), commandString, "<string>").build();
724724
} else {
725-
assert inputFile != null;
726-
// the path is passed through a context option
725+
// the path is passed through a context option, may be empty when running from stdin
727726
src = Source.newBuilder(getLanguageId(), "__graalpython__.run_path()", "<internal>").internal(true).build();
728727
}
729728
context.eval(src);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
5050
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
5151

5252
import java.io.IOException;
53+
import java.io.InputStreamReader;
5354
import java.io.PrintWriter;
5455
import java.nio.charset.StandardCharsets;
5556
import java.util.List;
@@ -246,7 +247,7 @@ PNone run() {
246247
PythonContext context = getContext();
247248
String inputFilePath = context.getOption(PythonOptions.InputFilePath);
248249
PythonModule sysModule = context.getSysModule();
249-
boolean needsMainImporter = getImporter(sysModule, inputFilePath);
250+
boolean needsMainImporter = !inputFilePath.isEmpty() && getImporter(sysModule, inputFilePath);
250251
if (needsMainImporter) {
251252
Object sysPath = sysModule.getAttribute("path");
252253
PyObjectCallMethodObjArgs.getUncached().execute(null, sysPath, "insert", 0, inputFilePath);
@@ -264,11 +265,19 @@ PNone run() {
264265
return PNone.NONE;
265266
}
266267

267-
// Equivalent of CPython's pymain_run_file
268+
// Equivalent of CPython's pymain_run_file and pymain_run_stdin
268269
private void runFile(PythonContext context, String inputFilePath) {
269270
Source source;
270271
try {
271-
source = Source.newBuilder(PythonLanguage.ID, context.getPublicTruffleFileRelaxed(inputFilePath)).mimeType(PythonLanguage.MIME_TYPE).build();
272+
Source.SourceBuilder builder;
273+
if (inputFilePath.isEmpty()) {
274+
// Reading from stdin
275+
builder = Source.newBuilder(PythonLanguage.ID, new InputStreamReader(context.getStandardIn()), "<stdin>");
276+
} else {
277+
TruffleFile file = context.getPublicTruffleFileRelaxed(inputFilePath);
278+
builder = Source.newBuilder(PythonLanguage.ID, file);
279+
}
280+
source = builder.mimeType(PythonLanguage.MIME_TYPE).build();
272281
// TODO we should handle non-IO errors better
273282
} catch (IOException e) {
274283
ErrorAndMessagePair error = OSErrorEnum.fromException(e);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -362,40 +362,14 @@ public static boolean isIdentifier(String value) {
362362
return false;
363363
}
364364
int c = value.codePointAt(pos);
365-
int type = Character.getType(c);
366-
if (c != '_') {
367-
// Unicode XID_Start
368-
switch (type) {
369-
case Character.UPPERCASE_LETTER:
370-
case Character.LOWERCASE_LETTER:
371-
case Character.TITLECASE_LETTER:
372-
case Character.MODIFIER_LETTER:
373-
case Character.OTHER_LETTER:
374-
case Character.LETTER_NUMBER:
375-
break;
376-
default:
377-
return false;
378-
}
365+
if (c != '_' && !UCharacter.hasBinaryProperty(c, UProperty.XID_START)) {
366+
return false;
379367
}
380368
pos += Character.charCount(c);
381369
while (pos < value.length()) {
382370
c = value.codePointAt(pos);
383-
type = Character.getType(c);
384-
// Unicode XID_Continue
385-
switch (type) {
386-
case Character.UPPERCASE_LETTER:
387-
case Character.LOWERCASE_LETTER:
388-
case Character.TITLECASE_LETTER:
389-
case Character.MODIFIER_LETTER:
390-
case Character.OTHER_LETTER:
391-
case Character.LETTER_NUMBER:
392-
case Character.NON_SPACING_MARK:
393-
case Character.COMBINING_SPACING_MARK:
394-
case Character.DECIMAL_DIGIT_NUMBER:
395-
case Character.CONNECTOR_PUNCTUATION:
396-
break;
397-
default:
398-
return false;
371+
if (!UCharacter.hasBinaryProperty(c, UProperty.XID_CONTINUE)) {
372+
return false;
399373
}
400374
pos += Character.charCount(c);
401375
}

graalpython/lib-graalpython/_weakref.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -49,9 +49,9 @@ def _proxy_get(proxy):
4949

5050

5151
class ProxyType(object):
52-
def __init__(self, other):
52+
def __init__(self, other, callback=None):
5353
import weakref
54-
object.__setattr__(self, "_weakref", weakref.ref(other))
54+
object.__setattr__(self, "_weakref", weakref.ref(other, callback))
5555

5656
def __getattribute__(self, key):
5757
return getattr(_proxy_get(self), key)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From b1c948a07cfe2ffbb5e0954f0ee87dddd78e63ab Mon Sep 17 00:00:00 2001
2+
From: Michael Simacek <[email protected]>
3+
Date: Tue, 18 Jan 2022 15:54:16 +0100
4+
Subject: [PATCH] Adapt for GraalPython
5+
6+
---
7+
setup.py | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/setup.py b/setup.py
11+
index c6ee5bf..b398be9 100644
12+
--- a/setup.py
13+
+++ b/setup.py
14+
@@ -52,7 +52,7 @@ def show_message(*lines):
15+
print("=" * 74)
16+
17+
18+
-supports_speedups = platform.python_implementation() not in {"PyPy", "Jython"}
19+
+supports_speedups = platform.python_implementation() not in {"PyPy", "Jython", "GraalVM"}
20+
21+
if os.environ.get("CIBUILDWHEEL", "0") == "1" and supports_speedups:
22+
run_setup(True)
23+
--
24+
2.31.1
25+

mx.graalpython/mx_graalpython.py

Lines changed: 2 additions & 2 deletions
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) 2013, Regents of the University of California
33
#
44
# All rights reserved.
@@ -1300,7 +1300,7 @@ def _python_checkpatchfiles():
13001300
content = listfile.read()
13011301
patchfile_pattern = re.compile(r"lib-graalpython/patches/([^/]+)/(sdist|whl)/.*\.patch")
13021302
checked = set()
1303-
allowed_licenses = ["MIT", "BSD", "MIT license", "PSF"]
1303+
allowed_licenses = ["MIT", "BSD", "BSD-3-Clause", "MIT license", "PSF"]
13041304
for line in content.split("\n"):
13051305
match = patchfile_pattern.search(line)
13061306
if match:

0 commit comments

Comments
 (0)