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