Skip to content

Commit 57c4c1b

Browse files
committed
Avoid warning when installing pinned package without a patch
1 parent e59c75a commit 57c4c1b

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

graalpython/lib-graalpython/patches/pip/whl/pip-22.2.2.patch

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ index 1af8978..15fee7f 100644
5858
# file in .data maps to same location as file in wheel root).
5959
diff --git a/pip/_internal/utils/graalpy.py b/pip/_internal/utils/graalpy.py
6060
new file mode 100644
61-
index 0000000..b8e849b
61+
index 0000000..dd8f441
6262
--- /dev/null
6363
+++ b/pip/_internal/utils/graalpy.py
64-
@@ -0,0 +1,189 @@
64+
@@ -0,0 +1,188 @@
6565
+# ATTENTION: GraalPy uses existence of this module to verify that it is
6666
+# running a patched pip in pip_hook.py
6767
+import os
@@ -153,11 +153,9 @@ index 0000000..b8e849b
153153
+ versions.add(version)
154154
+ return versions
155155
+
156-
+ def get_patch_rule(self, name, requested_version, dist_type):
156+
+ def get_matching_rule(self, name, requested_version, dist_type):
157157
+ if metadata := self.get_rules(name):
158158
+ for rule in metadata:
159-
+ if 'patch' not in rule:
160-
+ continue
161159
+ if rule.get('dist-type', dist_type) != dist_type:
162160
+ continue
163161
+ if not self.rule_matches_version(rule, requested_version):
@@ -199,7 +197,7 @@ index 0000000..b8e849b
199197
+ return
200198
+
201199
+ name = name_ver_match.group('name')
202-
+ version_spec = name_ver_match.group('version')
200+
+ version = name_ver_match.group('version')
203201
+ suffix = name_ver_match.group('suffix')
204202
+ is_wheel = suffix == "whl"
205203
+
@@ -208,35 +206,36 @@ index 0000000..b8e849b
208206
+ return
209207
+
210208
+ # 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:
212210
+ return
213211
+
214212
+ print(f"Looking for GraalPy patches for {name}")
215213
+ repository = get_patch_repository()
216214
+
217215
+ if is_wheel:
218216
+ # 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')
220218
+ else:
221219
+ # 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')):
226224
+ # we may need to change wd if we are actually patching a source distribution
227225
+ # with a patch intended for a binary distribution, because in the source
228226
+ # distribution the actual deployed sources may be in a subdirectory (typically "src")
229227
+ 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))
240239
+ elif version_specs := repository.get_suggested_version_specs(name):
241240
+ print("We have patches to make this package work on GraalVM for some version(s).")
242241
+ print("If installing or running fails, consider using one of the versions that we have patches for:")

0 commit comments

Comments
 (0)