@@ -58,10 +58,10 @@ index 1af8978..15fee7f 100644
58
58
# file in .data maps to same location as file in wheel root).
59
59
diff --git a/pip/_internal/utils/graalpy.py b/pip/_internal/utils/graalpy.py
60
60
new file mode 100644
61
- index 0000000..b8e849b
61
+ index 0000000..dd8f441
62
62
--- /dev/null
63
63
+++ b/pip/_internal/utils/graalpy.py
64
- @@ -0,0 +1,189 @@
64
+ @@ -0,0 +1,188 @@
65
65
+ # ATTENTION: GraalPy uses existence of this module to verify that it is
66
66
+ # running a patched pip in pip_hook.py
67
67
+ import os
@@ -153,11 +153,9 @@ index 0000000..b8e849b
153
153
+ versions.add(version)
154
154
+ return versions
155
155
+
156
- + def get_patch_rule (self, name, requested_version, dist_type):
156
+ + def get_matching_rule (self, name, requested_version, dist_type):
157
157
+ if metadata := self.get_rules(name):
158
158
+ for rule in metadata:
159
- + if 'patch' not in rule:
160
- + continue
161
159
+ if rule.get('dist-type', dist_type) != dist_type:
162
160
+ continue
163
161
+ if not self.rule_matches_version(rule, requested_version):
@@ -199,7 +197,7 @@ index 0000000..b8e849b
199
197
+ return
200
198
+
201
199
+ name = name_ver_match.group('name')
202
- + version_spec = name_ver_match.group('version')
200
+ + version = name_ver_match.group('version')
203
201
+ suffix = name_ver_match.group('suffix')
204
202
+ is_wheel = suffix == "whl"
205
203
+
@@ -208,35 +206,36 @@ index 0000000..b8e849b
208
206
+ return
209
207
+
210
208
+ # When we patch a sdist, pip may call us again to process the wheel produced from it
211
- + if (name, version_spec ) in __already_patched:
209
+ + if (name, version ) in __already_patched:
212
210
+ return
213
211
+
214
212
+ print(f"Looking for GraalPy patches for {name}")
215
213
+ repository = get_patch_repository()
216
214
+
217
215
+ if is_wheel:
218
216
+ # patches intended for binary distribution:
219
- + patch_rule = repository.get_patch_rule (name, version_spec , 'wheel')
217
+ + rule = repository.get_matching_rule (name, version , 'wheel')
220
218
+ else:
221
219
+ # patches intended for source distribution if applicable
222
- + patch_rule = repository.get_patch_rule (name, version_spec , 'sdist')
223
- + if not patch_rule :
224
- + patch_rule = repository.get_patch_rule (name, version_spec , 'wheel')
225
- + if patch_rule and (subdir := patch_rule .get('subdir')):
220
+ + rule = repository.get_matching_rule (name, version , 'sdist')
221
+ + if not rule :
222
+ + rule = repository.get_matching_rule (name, version , 'wheel')
223
+ + if rule and (subdir := rule .get('subdir')):
226
224
+ # we may need to change wd if we are actually patching a source distribution
227
225
+ # with a patch intended for a binary distribution, because in the source
228
226
+ # distribution the actual deployed sources may be in a subdirectory (typically "src")
229
227
+ location = os.path.join(location, subdir)
230
- + if patch_rule:
231
- + print(f"Patching package {name} using {patch_rule['patch']}")
232
- + try:
233
- + subprocess.run(["patch", "-f", "-d", location, "-p1", "-i", str(patch_rule['patch'])], check=True)
234
- + except FileNotFoundError:
235
- + print(
236
- + "WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager.")
237
- + except subprocess.CalledProcessError:
238
- + print(f"Applying GraalPy patch failed for {name}. The package may still work.")
239
- + __already_patched.add((name, version_spec))
228
+ + if rule:
229
+ + if patch := rule.get('patch'):
230
+ + print(f"Patching package {name} using {patch}")
231
+ + try:
232
+ + subprocess.run(["patch", "-f", "-d", location, "-p1", "-i", str(patch)], check=True)
233
+ + except FileNotFoundError:
234
+ + print(
235
+ + "WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager.")
236
+ + except subprocess.CalledProcessError:
237
+ + print(f"Applying GraalPy patch failed for {name}. The package may still work.")
238
+ + __already_patched.add((name, version))
240
239
+ elif version_specs := repository.get_suggested_version_specs(name):
241
240
+ print("We have patches to make this package work on GraalVM for some version(s).")
242
241
+ print("If installing or running fails, consider using one of the versions that we have patches for:")
0 commit comments