Skip to content

Commit 5f71e79

Browse files
committed
[GR-43614] [GR-43615] Fix pytype so that types_pytz tests pass on graalpy
PullRequest: graalpython/2617
2 parents 1e7b121 + 8c495d9 commit 5f71e79

File tree

8 files changed

+195
-4
lines changed

8 files changed

+195
-4
lines changed

graalpython/com.oracle.graal.python.cext/src/pystate.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, 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
@@ -55,6 +55,12 @@ PyThreadState * PyThreadState_Get() {
5555
return polyglot_invoke(PY_TRUFFLE_CEXT, "PyThreadState_Get");
5656
}
5757

58+
void PyThreadState_Clear(PyThreadState *tstate) {
59+
}
60+
61+
void PyThreadState_DeleteCurrent(void) {
62+
}
63+
5864
int64_t
5965
PyInterpreterState_GetID(PyInterpreterState *interp)
6066
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.ServiceLoader;
5656
import java.util.logging.Level;
5757

58+
import com.oracle.graal.python.builtins.modules.TracemallocModuleBuiltins;
5859
import org.graalvm.nativeimage.ImageInfo;
5960

6061
import com.oracle.graal.python.PythonLanguage;
@@ -575,7 +576,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
575576
new PythonCextWarnBuiltins(),
576577
new WeakRefModuleBuiltins(),
577578
new ReferenceTypeBuiltins(),
578-
new WarningsModuleBuiltins(),
579+
new TracemallocModuleBuiltins(),
579580
new ContextVarBuiltins(),
580581
new ContextBuiltins(),
581582
new TokenBuiltins(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.builtins.modules;
42+
43+
import static com.oracle.graal.python.nodes.BuiltinNames.J__TRACEMALLOC;
44+
45+
import java.util.List;
46+
47+
import com.oracle.graal.python.builtins.Builtin;
48+
import com.oracle.graal.python.builtins.CoreFunctions;
49+
import com.oracle.graal.python.builtins.Python3Core;
50+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
51+
import com.oracle.graal.python.builtins.PythonBuiltins;
52+
import com.oracle.graal.python.nodes.PRaiseNode;
53+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
54+
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
55+
import com.oracle.truffle.api.dsl.Cached;
56+
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
57+
import com.oracle.truffle.api.dsl.NodeFactory;
58+
import com.oracle.truffle.api.dsl.Specialization;
59+
60+
@CoreFunctions(defineModule = J__TRACEMALLOC)
61+
public class TracemallocModuleBuiltins extends PythonBuiltins {
62+
63+
@Override
64+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
65+
return TracemallocModuleBuiltinsFactory.getFactories();
66+
}
67+
68+
@Override
69+
public void initialize(Python3Core core) {
70+
super.initialize(core);
71+
}
72+
73+
@Builtin(name = "_get_object_traceback", minNumOfPositionalArgs = 1)
74+
@GenerateNodeFactory
75+
abstract static class GetObjectTracebackNode extends PythonBuiltinNode {
76+
@Specialization
77+
static Object getObjectTraceback(Object obj,
78+
@Cached PRaiseNode raiseNode) {
79+
throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError);
80+
}
81+
}
82+
83+
@Builtin(name = "_get_traces")
84+
@GenerateNodeFactory
85+
abstract static class GetTracesNode extends PythonBuiltinNode {
86+
@Specialization
87+
static Object getTraces(
88+
@Cached PRaiseNode raiseNode) {
89+
throw raiseNode.raise(PythonBuiltinClassType.NotImplementedError);
90+
}
91+
}
92+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,21 @@ public int doit(PyCapsule o, TruffleString name,
368368
}
369369
}
370370

371+
@Specialization(guards = "isNoValue(name)")
372+
public int doit(PyCapsule o, @SuppressWarnings("unused") PNone name,
373+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
374+
try {
375+
if (o.getPointer() == null) {
376+
throw raise(ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, "PyCapsule_SetName");
377+
}
378+
o.setName(null);
379+
return 0;
380+
} catch (PException e) {
381+
transformExceptionToNativeNode.execute(e);
382+
return -1;
383+
}
384+
}
385+
371386
@Fallback
372387
public Object doit(VirtualFrame ignoredFrame, Object ignoredo, Object ignored) {
373388
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/BuiltinNames.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, 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
@@ -365,6 +365,9 @@ public abstract class BuiltinNames {
365365
public static final String J__WARNINGS = "_warnings";
366366
public static final TruffleString T__WARNINGS = tsLiteral(J__WARNINGS);
367367

368+
public static final String J__TRACEMALLOC = "_tracemalloc";
369+
public static final TruffleString T__TRACEMALLOC = tsLiteral(J__TRACEMALLOC);
370+
368371
public static final String J_POSIX = "posix";
369372
public static final TruffleString T_POSIX = tsLiteral(J_POSIX);
370373

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
From 8dfcef1719d719b32a9b9f85828dfbc1521064e3 Mon Sep 17 00:00:00 2001
2+
From: Ondrej Tethal <[email protected]>
3+
Date: Fri, 20 Jan 2023 14:47:24 +0100
4+
Subject: [PATCH] Remove libcst dependency
5+
6+
---
7+
pytype.egg-info/requires.txt | 1 -
8+
pytype/io.py | 11 -----------
9+
setup.cfg | 1 -
10+
3 files changed, 13 deletions(-)
11+
12+
diff --git a/pytype.egg-info/requires.txt b/pytype.egg-info/requires.txt
13+
index 9f5233d..ddbfbec 100644
14+
--- a/pytype.egg-info/requires.txt
15+
+++ b/pytype.egg-info/requires.txt
16+
@@ -1,7 +1,6 @@
17+
attrs>=21.4.0
18+
importlab>=0.8
19+
jinja2>=3.1.2
20+
-libcst>=0.4.9
21+
networkx<2.8.4
22+
ninja>=1.10.0.post2
23+
pydot>=1.4.2
24+
diff --git a/pytype/io.py b/pytype/io.py
25+
index 8ca0785..67d3274 100644
26+
--- a/pytype/io.py
27+
+++ b/pytype/io.py
28+
@@ -9,8 +9,6 @@ import traceback
29+
30+
from typing import Optional
31+
32+
-import libcst
33+
-
34+
from pytype import __version__
35+
from pytype import analyze
36+
from pytype import config
37+
@@ -176,10 +174,6 @@ def check_or_generate_pyi(options, loader=None, ctx=None) -> AnalysisResult:
38+
errorlog.python_compiler_error(options.input, e.lineno, e.message)
39+
except IndentationError as e:
40+
errorlog.python_compiler_error(options.input, e.lineno, e.msg)
41+
- except libcst.ParserSyntaxError as e:
42+
- # TODO(rechen): We can get rid of this branch once we delete
43+
- # directors.parser_libcst.
44+
- errorlog.python_compiler_error(options.input, e.raw_line, e.message)
45+
except SyntaxError as e:
46+
errorlog.python_compiler_error(options.input, e.lineno, e.msg)
47+
except directors.SkipFileError:
48+
@@ -339,11 +333,6 @@ def wrap_pytype_exceptions(exception_type, filename=""):
49+
except pyc.CompileError as e:
50+
raise exception_type("Error reading file %s at line %s: %s" %
51+
(filename, e.lineno, e.error)) from e
52+
- except libcst.ParserSyntaxError as e:
53+
- # TODO(rechen): We can get rid of this branch once we delete
54+
- # directors.parser_libcst.
55+
- raise exception_type("Error reading file %s at line %s: %s" %
56+
- (filename, e.raw_line, e.message)) from e
57+
except SyntaxError as e:
58+
raise exception_type("Error reading file %s at line %s: %s" %
59+
(filename, e.lineno, e.msg)) from e
60+
diff --git a/setup.cfg b/setup.cfg
61+
index a6f0c9e..96ba2e3 100644
62+
--- a/setup.cfg
63+
+++ b/setup.cfg
64+
@@ -33,7 +33,6 @@ install_requires =
65+
attrs>=21.4.0
66+
importlab>=0.8
67+
jinja2>=3.1.2
68+
- libcst>=0.4.9
69+
networkx<2.8.4
70+
ninja>=1.10.0.post2
71+
pydot>=1.4.2
72+
--
73+
2.25.1
74+

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ def _python_checkpatchfiles():
17801780
allowed_licenses = [
17811781
"MIT", "BSD", "BSD-3-Clause", "BSD 3-Clause License", "BSD or Apache License, Version 2.0",
17821782
"MIT license", "PSF", "BSD-3-Clause OR Apache-2.0", "Apache", "Apache License", "new BSD",
1783-
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0",
1783+
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0", "Apache 2.0",
17841784
]
17851785
for line in content.split("\n"):
17861786
if not line or os.stat(line).st_size == 0:

0 commit comments

Comments
 (0)