Skip to content

Commit adcb38a

Browse files
committed
[DEBUG] Really dirty hack around pip fake-venv
Signed-off-by: Cristian Le <[email protected]>
1 parent ceac2a6 commit adcb38a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/scikit_build_core/repair_wheel/__init__.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@
2626
"WheelRepairer",
2727
]
2828

29+
DIR = Path(__file__).parent.resolve()
30+
31+
32+
def _get_buildenv_platlib() -> str:
33+
# Normally we could `sysconfig.get_path("platlib")` directly, but pip fake-venv breaks it
34+
platlib_path = sysconfig.get_path("platlib")
35+
purelib_path = sysconfig.get_path("purelib")
36+
real_purelib_path = DIR.parent.parent
37+
if real_purelib_path.samefile(purelib_path):
38+
# Here is the normal state if we are in a real venv
39+
return platlib_path
40+
# Otherwise we need to trick it to giving us the real path
41+
data_path = sysconfig.get_path("data")
42+
platlib_relative_path = Path(platlib_path).relative_to(data_path)
43+
purelib_relative_path = Path(purelib_path).relative_to(data_path)
44+
45+
# removesuffix(purelib_relative_path)
46+
if str(real_purelib_path).rfind(str(purelib_relative_path)) == -1:
47+
logger.warning(
48+
"Could not figure out the true build-env path:\n"
49+
"sysconfig_purelib = {sysconfig_purelib}\n"
50+
"scikit-build-core_purelib = {real_purelib}\n",
51+
sysconfig_purelib=purelib_path,
52+
real_purelib=real_purelib_path,
53+
)
54+
return platlib_path
55+
real_root = str(real_purelib_path)[: -len(str(purelib_relative_path))]
56+
real_platlib_path = str(Path(real_root) / platlib_relative_path)
57+
# Yet another dirty trick necessary
58+
real_platlib_path = real_platlib_path.replace("/overlay/", "/normal/")
59+
logger.debug("Calculated real_platlib_path = {}", real_platlib_path)
60+
return str(real_platlib_path)
61+
2962

3063
@dataclasses.dataclass()
3164
class WheelRepairer(ABC):
@@ -98,7 +131,7 @@ def path_relative_site_packages(
98131
path.relative_to(self.wheel_dirs["platlib"])
99132
except ValueError:
100133
# Otherwise check if the path is relative to build environment
101-
path = path.relative_to(sysconfig.get_path("platlib"))
134+
path = path.relative_to(_get_buildenv_platlib())
102135
# Mock the path to be in the wheel install platlib
103136
path = self.wheel_dirs["platlib"] / path
104137
return Path(os.path.relpath(path, relative_to))

0 commit comments

Comments
 (0)