|
31 | 31 | "WindowsWheelRepairer", |
32 | 32 | ] |
33 | 33 |
|
| 34 | +DIR = Path(__file__).parent.resolve() |
| 35 | + |
| 36 | + |
| 37 | +@functools.lru_cache(1) |
| 38 | +def _get_buildenv_platlib() -> str: |
| 39 | + # Normally we could `sysconfig.get_path("platlib")` directly, but pip fake-venv breaks it |
| 40 | + platlib_path = sysconfig.get_path("platlib") |
| 41 | + purelib_path = sysconfig.get_path("purelib") |
| 42 | + real_purelib_path = DIR.parent.parent |
| 43 | + if real_purelib_path.samefile(purelib_path): |
| 44 | + # Here is the normal state if we are in a real venv |
| 45 | + return str(Path(platlib_path).resolve()) |
| 46 | + # Otherwise we need to trick it to giving us the real path |
| 47 | + data_path = sysconfig.get_path("data") |
| 48 | + platlib_relative_path = Path(platlib_path).relative_to(data_path) |
| 49 | + purelib_relative_path = Path(purelib_path).relative_to(data_path) |
| 50 | + |
| 51 | + # removesuffix(purelib_relative_path) |
| 52 | + if str(real_purelib_path).rfind(str(purelib_relative_path)) == -1: |
| 53 | + logger.warning( |
| 54 | + "Could not figure out the true build-env path:\n" |
| 55 | + "sysconfig_purelib = {sysconfig_purelib}\n" |
| 56 | + "scikit-build-core_purelib = {real_purelib}\n", |
| 57 | + sysconfig_purelib=purelib_path, |
| 58 | + real_purelib=real_purelib_path, |
| 59 | + ) |
| 60 | + return platlib_path |
| 61 | + real_root = str(real_purelib_path)[: -len(str(purelib_relative_path))] |
| 62 | + real_platlib_path = str(Path(real_root) / platlib_relative_path) |
| 63 | + # Yet another dirty trick necessary |
| 64 | + real_platlib_path = real_platlib_path.replace( |
| 65 | + os.path.normpath("/overlay/"), |
| 66 | + os.path.normpath("/normal/"), |
| 67 | + ) |
| 68 | + logger.debug("Calculated real_platlib_path = {}", real_platlib_path) |
| 69 | + return str(real_platlib_path) |
| 70 | + |
34 | 71 |
|
35 | 72 | @dataclasses.dataclass() |
36 | 73 | class WheelRepairer(ABC): |
@@ -103,7 +140,7 @@ def path_relative_site_packages( |
103 | 140 | path.relative_to(self.wheel_dirs["platlib"]) |
104 | 141 | except ValueError: |
105 | 142 | # Otherwise check if the path is relative to build environment |
106 | | - path = path.relative_to(sysconfig.get_path("platlib")) |
| 143 | + path = path.relative_to(_get_buildenv_platlib()) |
107 | 144 | # Mock the path to be in the wheel install platlib |
108 | 145 | path = self.wheel_dirs["platlib"] / path |
109 | 146 | return Path(os.path.relpath(path, relative_to)) |
|
0 commit comments