Skip to content

Commit 20874b8

Browse files
committed
Dirty hack around pip fake-venv
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent 20cba8f commit 20874b8

File tree

1 file changed

+39
-1
lines changed
  • src/scikit_build_core/repair_wheel

1 file changed

+39
-1
lines changed

src/scikit_build_core/repair_wheel/base.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,44 @@
2222
from ..file_api.model.codemodel import Configuration, Target
2323

2424

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+
2563
@dataclasses.dataclass
2664
class WheelRepairer(ABC):
2765
"""Abstract wheel repairer."""
@@ -93,7 +131,7 @@ def path_relative_site_packages(
93131
path.relative_to(self.wheel_dirs["platlib"])
94132
except ValueError:
95133
# 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())
97135
# Mock the path to be in the wheel install platlib
98136
path = self.wheel_dirs["platlib"] / path
99137
return Path(os.path.relpath(path, relative_to))

0 commit comments

Comments
 (0)