Skip to content

Commit a7b3063

Browse files
committed
[GR-44383] Run autopatch_capi also in ginstall.
PullRequest: graalpython/2645
2 parents 220d576 + d968133 commit a7b3063

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

graalpython/lib-graalpython/modules/ginstall.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,16 +636,25 @@ def _install_from_url(url, package, extra_opts=None, add_cflags="", ignore_error
636636
build_cmd = user_build_cmd.split(" ")
637637

638638
bare_name = _download_with_curl_and_extract(tempdir, url, quiet=quiet)
639+
extracted_dir = os.path.join(tempdir, bare_name, "")
639640

640641
file_realpath = os.path.dirname(os.path.realpath(__file__))
641642
patches_dir = os.path.join(Path(file_realpath).parent, 'patches', package)
642643
# empty match group to have the same groups range as in pip_hook
643644
# unlike with pip, the version number may not be available at all
644645
versions = re.search("()(\\d+)?(.\\d+)?(.\\d+)?", "" if version is None else version)
645646

647+
if "--no-autopatch" not in extra_opts:
648+
# run autopatch_capi
649+
spec = importlib.util.spec_from_file_location("autopatch_capi", os.path.join(file_realpath, "autopatch_capi.py"))
650+
autopatch_capi = importlib.util.module_from_spec(spec)
651+
spec.loader.exec_module(autopatch_capi)
652+
info("auto-patching {}", extracted_dir)
653+
autopatch_capi.auto_patch_tree(extracted_dir)
654+
646655
patch_file_path = first_existing(package, versions, os.path.join(patches_dir, "sdist"), ".patch")
647656
if patch_file_path:
648-
run_cmd(["patch", "-d", os.path.join(tempdir, bare_name, ""), "-p1", "-i", patch_file_path], quiet=quiet)
657+
run_cmd(["patch", "-d", extracted_dir, "-p1", "-i", patch_file_path], quiet=quiet)
649658

650659
whl_patches_dir = os.path.join(patches_dir, "whl")
651660
patch_file_path = first_existing(package, versions, whl_patches_dir, ".patch")
@@ -816,6 +825,7 @@ def main(argv):
816825
install_parser.add_argument("--prefix", help="user-site path prefix")
817826
install_parser.add_argument("--user", action='store_true', help="install into user site")
818827
install_parser.add_argument("--debug-build", action="store_true", help="Enable debug options when building")
828+
install_parser.add_argument("--no-autopatch", action="store_true", help="Do not autopatch C extensions.")
819829

820830
uninstall_parser = subparsers.add_parser(
821831
"uninstall", help="remove installation folder of a local package", )
@@ -865,6 +875,8 @@ def main(argv):
865875
extra_opts += ["--prefix", args.prefix]
866876
if args.user:
867877
extra_opts += ["--user"]
878+
if args.no_autopatch:
879+
extra_opts += ["--no-autopatch"]
868880

869881
for pkg in args.package.split(","):
870882
if os.path.isfile(pkg):

0 commit comments

Comments
 (0)