Skip to content

Commit 3d4d050

Browse files
committed
[GR-32119] Pip hook, add ability to add extra patch locations.
PullRequest: graalpython/1857
2 parents 602a1a5 + edf2f06 commit 3d4d050

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

graalpython/lib-graalpython/pip_hook.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
class PipLoader:
4444
def __init__(self, real_spec):
4545
self.real_spec = real_spec
46+
import os
47+
self._patches_base_dirs = [os.path.join(__graalpython__.core_home, "patches")]
48+
if hasattr(__graalpython__, "tdebug"):
49+
self._patches_base_dirs += os.environ.get('PIPLOADER_PATCHES_BASE_DIRS', "").split(",")
4650

4751
def create_module(self, spec):
4852
return self.real_spec.loader.create_module(self.real_spec)
@@ -72,7 +76,6 @@ def unpack_file(filename, location, *args, **kwargs):
7276

7377
package_name = name_ver_match.group(1)
7478
is_sdist = name_ver_match.group(5) in ("tar.gz", "zip")
75-
patches_base_dir = os.path.join(__graalpython__.core_home, "patches")
7679

7780
# NOTE: Following 3 functions are duplicated in ginstall.py:
7881
# creates a search list of a versioned file:
@@ -119,16 +122,17 @@ def apply_first_existing(dir, suffix, wd=None):
119122

120123
print("Looking for Graal Python patches for " + package_name)
121124

122-
# patches intended for binary distribution:
123-
# we may need to change wd if we are actually patching the source distribution
124-
bdist_dir = os.path.join(patches_base_dir, package_name, "whl")
125-
bdist_patch_wd = read_first_existing(package_name, name_ver_match, bdist_dir, ".dir") if is_sdist else None
126-
apply_first_existing(bdist_dir, ".patch", bdist_patch_wd)
127-
128-
# patches intended for source distribution if applicable
129-
if is_sdist:
130-
sdist_dir = os.path.join(patches_base_dir, package_name, "sdist")
131-
apply_first_existing(sdist_dir, ".patch")
125+
for pbd in self._patches_base_dirs:
126+
# patches intended for binary distribution:
127+
# we may need to change wd if we are actually patching the source distribution
128+
bdist_dir = os.path.join(pbd, package_name, "whl")
129+
bdist_patch_wd = read_first_existing(package_name, name_ver_match, bdist_dir, ".dir") if is_sdist else None
130+
apply_first_existing(bdist_dir, ".patch", bdist_patch_wd)
131+
132+
# patches intended for source distribution if applicable
133+
if is_sdist:
134+
sdist_dir = os.path.join(pbd, package_name, "sdist")
135+
apply_first_existing(sdist_dir, ".patch")
132136

133137
return result
134138

0 commit comments

Comments
 (0)