Skip to content

Commit 47abfbb

Browse files
committed
[GR-53373] Update Cython patch to recythonize files after unpatched Cython
PullRequest: graalpython/3326
2 parents a792079 + 8b8437d commit 47abfbb

File tree

6 files changed

+120
-14
lines changed

6 files changed

+120
-14
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -126,6 +126,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
126126
@Override
127127
public void initialize(Python3Core core) {
128128
super.initialize(core);
129+
130+
addBuiltinConstant("error", PythonBuiltinClassType.OSError);
131+
129132
addBuiltinConstant("RUSAGE_CHILDREN", RUSAGE_CHILDREN);
130133
addBuiltinConstant("RUSAGE_SELF", RUSAGE_SELF);
131134
addBuiltinConstant("RUSAGE_THREAD", RUSAGE_THREAD);

graalpython/lib-graalpython/patches/Cython/Cython-0.29.32.patch

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
2-
index 7eb55e2..76d4857 100644
2+
index 7eb55e2..1fbab30 100644
33
--- a/Cython/Build/Dependencies.py
44
+++ b/Cython/Build/Dependencies.py
5-
@@ -1094,6 +1094,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
5+
@@ -1060,6 +1060,12 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
6+
else:
7+
dep_timestamp, dep = deps.newest_dependency(source)
8+
priority = 2 - (dep in deps.immediate_dependencies(source))
9+
+ # GraalPy change: force recythonize if not cythonized by our patched version
10+
+ if os.path.exists(c_file):
11+
+ with open(c_file, 'rb') as f:
12+
+ # We modify the watermark to include graalpy
13+
+ if not b'graalpy' in f.read(100):
14+
+ c_timestamp = -1
15+
if force or c_timestamp < dep_timestamp:
16+
if not quiet and not force:
17+
if source == dep:
18+
@@ -1094,6 +1100,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
619
progress = progress_fmt.format(i+1, N)
720
to_compile[i] = to_compile[i][1:] + (progress,)
821

@@ -101,6 +114,17 @@ index 7361a55..6c4d9d9 100644
101114
entry.in_cinclude = self.in_cinclude
102115
entry.create_wrapper = create_wrapper
103116
if name:
117+
diff --git a/Cython/Compiler/Version.py b/Cython/Compiler/Version.py
118+
index dcb561f..c2c06a0 100644
119+
--- a/Cython/Compiler/Version.py
120+
+++ b/Cython/Compiler/Version.py
121+
@@ -6,4 +6,5 @@ from .. import __version__ as version
122+
123+
# For 'generated by' header line in C files.
124+
125+
-watermark = str(version)
126+
+# GraalPy change: watermark our patched version
127+
+watermark = f'{version}-graalpy'
104128
diff --git a/Cython/Includes/cpython/datetime.pxd b/Cython/Includes/cpython/datetime.pxd
105129
index cd0f907..712cd92 100644
106130
--- a/Cython/Includes/cpython/datetime.pxd

graalpython/lib-graalpython/patches/Cython/Cython-0.29.37.patch

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
2-
index 92fa96a..2885a4f 100644
2+
index 92fa96a..8864b78 100644
33
--- a/Cython/Build/Dependencies.py
44
+++ b/Cython/Build/Dependencies.py
5-
@@ -1082,6 +1082,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
5+
@@ -1048,6 +1048,12 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
6+
else:
7+
dep_timestamp, dep = deps.newest_dependency(source)
8+
priority = 2 - (dep in deps.immediate_dependencies(source))
9+
+ # GraalPy change: force recythonize if not cythonized by our patched version
10+
+ if os.path.exists(c_file):
11+
+ with open(c_file, 'rb') as f:
12+
+ # We modify the watermark to include graalpy
13+
+ if not b'graalpy' in f.read(100):
14+
+ c_timestamp = -1
15+
if force or c_timestamp < dep_timestamp:
16+
if not quiet and not force:
17+
if source == dep:
18+
@@ -1082,6 +1088,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
619
progress = progress_fmt.format(i+1, N)
720
to_compile[i] = to_compile[i][1:] + (progress,)
821

@@ -101,6 +114,17 @@ index 7361a55..6c4d9d9 100644
101114
entry.in_cinclude = self.in_cinclude
102115
entry.create_wrapper = create_wrapper
103116
if name:
117+
diff --git a/Cython/Compiler/Version.py b/Cython/Compiler/Version.py
118+
index dcb561f..c2c06a0 100644
119+
--- a/Cython/Compiler/Version.py
120+
+++ b/Cython/Compiler/Version.py
121+
@@ -6,4 +6,5 @@ from .. import __version__ as version
122+
123+
# For 'generated by' header line in C files.
124+
125+
-watermark = str(version)
126+
+# GraalPy change: watermark our patched version
127+
+watermark = f'{version}-graalpy'
104128
diff --git a/Cython/Includes/cpython/datetime.pxd b/Cython/Includes/cpython/datetime.pxd
105129
index cd0f907..712cd92 100644
106130
--- a/Cython/Includes/cpython/datetime.pxd
@@ -154,7 +178,7 @@ index 099b3c4..0692df0 100644
154178
cval = ((PyComplexObject *)o)->cval;
155179
else
156180
diff --git a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c
157-
index aaa8a8e..152e9dc 100644
181+
index aaa8a8e..e60a5e0 100644
158182
--- a/Cython/Utility/Coroutine.c
159183
+++ b/Cython/Utility/Coroutine.c
160184
@@ -531,8 +531,7 @@ static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *$lo
@@ -221,7 +245,7 @@ index 93f577f..5dac1d7 100644
221245
#endif
222246
else if (PyMethod_Check(method)) {
223247
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
224-
index cfff606..4a6a6ea 100644
248+
index cfff606..90876c6 100644
225249
--- a/Cython/Utility/ModuleSetupCode.c
226250
+++ b/Cython/Utility/ModuleSetupCode.c
227251
@@ -186,6 +186,48 @@

graalpython/lib-graalpython/patches/Cython/Cython-3.0.10.patch

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
2-
index 7de4065..e1589cd 100644
2+
index 7de4065..981011f 100644
33
--- a/Cython/Build/Dependencies.py
44
+++ b/Cython/Build/Dependencies.py
5-
@@ -1127,6 +1127,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
5+
@@ -1090,6 +1090,12 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
6+
else:
7+
dep_timestamp, dep = deps.newest_dependency(source)
8+
priority = 2 - (dep in deps.immediate_dependencies(source))
9+
+ # GraalPy change: force recythonize if not cythonized by our patched version
10+
+ if os.path.exists(c_file):
11+
+ with open(c_file, 'rb') as f:
12+
+ # We modify the watermark to include graalpy
13+
+ if not b'graalpy' in f.read(100):
14+
+ c_timestamp = -1
15+
if force or c_timestamp < dep_timestamp:
16+
if not quiet and not force:
17+
if source == dep:
18+
@@ -1127,6 +1133,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
619
progress = progress_fmt.format(i+1, N)
720
to_compile[i] = to_compile[i][1:] + (progress,)
821

@@ -103,6 +116,17 @@ index 5f088dd..a258bdc 100644
103116
entry.in_cinclude = self.in_cinclude
104117
entry.create_wrapper = create_wrapper
105118
if name:
119+
diff --git a/Cython/Compiler/Version.py b/Cython/Compiler/Version.py
120+
index dcb561f..c2c06a0 100644
121+
--- a/Cython/Compiler/Version.py
122+
+++ b/Cython/Compiler/Version.py
123+
@@ -6,4 +6,5 @@ from .. import __version__ as version
124+
125+
# For 'generated by' header line in C files.
126+
127+
-watermark = str(version)
128+
+# GraalPy change: watermark our patched version
129+
+watermark = f'{version}-graalpy'
106130
diff --git a/Cython/Includes/cpython/datetime.pxd b/Cython/Includes/cpython/datetime.pxd
107131
index 3dce395..77f8356 100644
108132
--- a/Cython/Includes/cpython/datetime.pxd

graalpython/lib-graalpython/patches/jaxlib/jaxlib-0.4.13.patch

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
diff --git a/jaxlib_build_backend.py b/jaxlib_build_backend.py
22
new file mode 100644
3-
index 000000000..5e6e553d2
3+
index 0000000..3727f7e
44
--- /dev/null
55
+++ b/jaxlib_build_backend.py
6-
@@ -0,0 +1,34 @@
6+
@@ -0,0 +1,39 @@
77
+import os
88
+import re
99
+import sys
@@ -32,21 +32,26 @@ index 000000000..5e6e553d2
3232
+
3333
+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
3434
+ with tempfile.TemporaryDirectory() as d:
35-
+ subprocess.run([sys.executable, 'build/build.py', '--output_path', d], check=True)
35+
+ cmd = [sys.executable, 'build/build.py', '--output_path', d]
36+
+ if num_jobs := os.environ.get('CORE_COUNT'):
37+
+ cmd += [f'--bazel_options=--jobs={num_jobs}']
38+
+ if max_mem := os.environ.get('MAX_MEMORY_GB'):
39+
+ cmd += [f'--bazel_options=--local_ram_resources={int(max_mem) * 1024}']
40+
+ subprocess.run(cmd, check=True)
3641
+ wheels = list(Path(d).glob('*.whl'))
3742
+ assert len(wheels) == 1, f"Expected 1 wheel, found {len(wheels)}"
3843
+ wheel = wheels[0]
3944
+ shutil.copyfile(wheel, Path(wheel_directory) / wheel.name)
4045
+ return str(wheel.name)
4146
diff --git a/pyproject.toml b/pyproject.toml
42-
index eb3eb4c1f..f521d3f36 100644
47+
index eb3eb4c..5876c7b 100644
4348
--- a/pyproject.toml
4449
+++ b/pyproject.toml
4550
@@ -1,6 +1,7 @@
4651
[build-system]
4752
-requires = ["setuptools", "wheel"]
4853
-build-backend = "setuptools.build_meta"
49-
+requires = ["setuptools", "wheel", "numpy"]
54+
+requires = ["setuptools", "wheel", "oldest-supported-numpy"]
5055
+build-backend = "jaxlib_build_backend"
5156
+backend-path = ["."]
5257

graalpython/lib-graalpython/patches/tokenizers/tokenizers-0.13.3.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,29 @@ index 6282c31..47e6b12 100644
2222

2323
[features]
2424
default = ["pyo3/extension-module"]
25+
diff --git a/tokenizers-lib/src/models/bpe/trainer.rs b/tokenizers-lib/src/models/bpe/trainer.rs
26+
index 43ab848..55f95f8 100644
27+
--- a/tokenizers-lib/src/models/bpe/trainer.rs
28+
+++ b/tokenizers-lib/src/models/bpe/trainer.rs
29+
@@ -518,15 +518,16 @@ impl BpeTrainer {
30+
let changes = top
31+
.pos
32+
.maybe_par_iter()
33+
- .flat_map(|i| {
34+
- let w = &words[*i] as *const _ as *mut _;
35+
+ .flat_map(|&i| {
36+
+ let word = &words[i] as *const _ as *mut Word;
37+
// We can merge each of these words in parallel here because each position
38+
// can be there only once (HashSet). So this is safe.
39+
unsafe {
40+
- let word: &mut Word = &mut (*w);
41+
- word.merge(top.pair.0, top.pair.1, new_token_id)
42+
+ // let word: &mut Word = &mut (*word);
43+
+ (*word)
44+
+ .merge(top.pair.0, top.pair.1, new_token_id)
45+
.into_iter()
46+
- .map(|c| (c, *i))
47+
+ .map(|c| (c, i))
48+
.collect::<Vec<_>>()
49+
}
50+
})

0 commit comments

Comments
 (0)