Skip to content

Commit 331f0f9

Browse files
committed
[DEBUG] Really dirty hack around pip fake-venv
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent f952820 commit 331f0f9

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/scikit_build_core/repair_wheel/__init__.py

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

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+
2966

3067
@dataclasses.dataclass()
3168
class WheelRepairer(ABC):
@@ -98,7 +135,7 @@ def path_relative_site_packages(
98135
path.relative_to(self.wheel_dirs["platlib"])
99136
except ValueError:
100137
# 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())
102139
# Mock the path to be in the wheel install platlib
103140
path = self.wheel_dirs["platlib"] / path
104141
return Path(os.path.relpath(path, relative_to))

0 commit comments

Comments
 (0)