|
22 | 22 | from ..file_api.model.codemodel import Configuration, Target |
23 | 23 |
|
24 | 24 |
|
| 25 | +DIR = Path(__file__).parent.resolve() |
| 26 | + |
| 27 | + |
| 28 | +@functools.lru_cache(1) |
| 29 | +def _get_buildenv_platlib() -> str: |
| 30 | + # Normally we could `sysconfig.get_path("platlib")` directly, but pip fake-venv breaks it |
| 31 | + platlib_path = sysconfig.get_path("platlib") |
| 32 | + purelib_path = sysconfig.get_path("purelib") |
| 33 | + real_purelib_path = DIR.parent.parent |
| 34 | + if real_purelib_path.samefile(purelib_path): |
| 35 | + # Here is the normal state if we are in a real venv |
| 36 | + return str(Path(platlib_path).resolve()) |
| 37 | + # Otherwise we need to trick it to giving us the real path |
| 38 | + data_path = sysconfig.get_path("data") |
| 39 | + platlib_relative_path = Path(platlib_path).relative_to(data_path) |
| 40 | + purelib_relative_path = Path(purelib_path).relative_to(data_path) |
| 41 | + |
| 42 | + # removesuffix(purelib_relative_path) |
| 43 | + if str(real_purelib_path).rfind(str(purelib_relative_path)) == -1: |
| 44 | + logger.warning( |
| 45 | + "Could not figure out the true build-env path:\n" |
| 46 | + "sysconfig_purelib = {sysconfig_purelib}\n" |
| 47 | + "scikit-build-core_purelib = {real_purelib}\n", |
| 48 | + sysconfig_purelib=purelib_path, |
| 49 | + real_purelib=real_purelib_path, |
| 50 | + ) |
| 51 | + return platlib_path |
| 52 | + real_root = str(real_purelib_path)[: -len(str(purelib_relative_path))] |
| 53 | + real_platlib_path = str(Path(real_root) / platlib_relative_path) |
| 54 | + # Yet another dirty trick necessary |
| 55 | + real_platlib_path = real_platlib_path.replace( |
| 56 | + os.path.normpath("/overlay/"), |
| 57 | + os.path.normpath("/normal/"), |
| 58 | + ) |
| 59 | + logger.debug("Calculated real_platlib_path = {}", real_platlib_path) |
| 60 | + return str(real_platlib_path) |
| 61 | + |
| 62 | + |
25 | 63 | @dataclasses.dataclass |
26 | 64 | class WheelRepairer(ABC): |
27 | 65 | """Abstract wheel repairer.""" |
@@ -93,7 +131,7 @@ def path_relative_site_packages( |
93 | 131 | path.relative_to(self.wheel_dirs["platlib"]) |
94 | 132 | except ValueError: |
95 | 133 | # Otherwise check if the path is relative to build environment |
96 | | - path = path.relative_to(sysconfig.get_path("platlib")) |
| 134 | + path = path.relative_to(_get_buildenv_platlib()) |
97 | 135 | # Mock the path to be in the wheel install platlib |
98 | 136 | path = self.wheel_dirs["platlib"] / path |
99 | 137 | return Path(os.path.relpath(path, relative_to)) |
|
0 commit comments