Skip to content

Commit

Permalink
Fix building for various packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwell175 committed Oct 27, 2024
1 parent e3d01eb commit c09b0f7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
37 changes: 35 additions & 2 deletions Lib/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import warnings
import platform
import rebuildpython
import re

import __np__
import __np__.packaging
Expand All @@ -29,6 +30,36 @@
builtin_packages = ensurepip._get_packages()


import pip._internal.utils.subprocess

call_subprocess_orig = pip._internal.utils.subprocess.call_subprocess

def our_call_subprocess(
cmd,
show_stdout = False,
cwd = None,
on_returncode = "raise",
extra_ok_returncodes = None,
extra_environ = None,
unset_environ = None,
spinner = None,
log_failed_cmd = True,
stdout_only = False,
*,
command_desc: str,
):
if extra_ok_returncodes is None:
our_extra_ok_returncodes = []
else:
our_extra_ok_returncodes = list(extra_ok_returncodes)

# Some packages cause this error code to be returned even if all is ok.
our_extra_ok_returncodes += [3221225477]
return call_subprocess_orig(cmd, show_stdout, cwd, on_returncode, our_extra_ok_returncodes, extra_environ, unset_environ, spinner, log_failed_cmd, stdout_only, command_desc=command_desc)

pip._internal.utils.subprocess.call_subprocess = our_call_subprocess


import pip._internal.pyproject

load_pyproject_toml_orig = pip._internal.pyproject.load_pyproject_toml
Expand All @@ -39,12 +70,14 @@ def our_load_pyproject_toml(use_pep517, pyproject_toml, setup_py, req_name):
# We will be taking over the build process.
if os.path.isfile(os.path.join(os.path.dirname(os.path.dirname(pyproject_toml)), "script.json")):
return pip._internal.pyproject.BuildSystemDetails(
[], "__np__.metabuild:managed_build", [], [real_pip_dir, os.path.dirname(__file__)])
[], "__np__.metabuild:managed_build", [], [os.path.dirname(__file__), real_pip_dir])

result = load_pyproject_toml_orig(use_pep517, pyproject_toml, setup_py, req_name)
if result is None:
return None
return pip._internal.pyproject.BuildSystemDetails(
[x for x in result.requires if re.split(r'[><=]', x, 1)[0] not in builtin_packages],
result.backend, result.check, result.backend_path + [real_pip_dir])
result.backend, result.check, [os.path.dirname(__file__), real_pip_dir] + result.backend_path)



Expand Down
6 changes: 5 additions & 1 deletion Lib/rebuildpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def run_rebuild():

ext_suffix = get_config_var("SO" if str is bytes else "EXT_SUFFIX")

extra_scan_dirs = []
extra_scan_dirs = [__np__.getDependencyInstallDir()]
if platform.system() == "Windows":
extra_scan_dirs.append(os.path.join(sysconfig.get_config_var('srcdir'), 'libs'))

Expand Down Expand Up @@ -384,6 +384,10 @@ def run_rebuild():
elif os.path.isfile(os.path.join(dir, lib) + ".lib"):
final_path = os.path.join(dir, lib) + ".lib"
break
else:
# System libraries need to not end in .lib since the linker will automatically append it.
if final_path.endswith(".lib"):
final_path = final_path[:-4]
if final_path not in final_lib_list:
final_lib_list.append(final_path)

Expand Down
7 changes: 6 additions & 1 deletion Lib/wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import sysconfig

# Make the standard wheel, the real wheel module.
# Need to keep a reference alive, or the module will loose all attributes.
Expand All @@ -14,5 +15,9 @@
del sys.path[0]
sys.modules["wheel"] = _wheel

def our_generic_abi():
return [wheel.vendored.packaging.tags._normalize_string(sysconfig.get_config_var("SOABI"))]

import wheel.vendored.packaging.tags
wheel.vendored.packaging.tags.INTERPRETER_SHORT_NAMES["nuitkapython"] = "np"
wheel.vendored.packaging.tags._generic_abi = our_generic_abi

0 comments on commit c09b0f7

Please sign in to comment.