Skip to content

Commit e1656cc

Browse files
Copilotnotatallshaw
andcommitted
Fix PEP 668 tests for Ubuntu 24.04 sitecustomize loading
Co-authored-by: notatallshaw <8070352+notatallshaw@users.noreply.github.com>
1 parent 5552048 commit e1656cc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/lib/venv.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,23 @@ def _customize_site(self) -> None:
194194
if self._sitecustomize is not None:
195195
contents += "\n" + self._sitecustomize
196196
sitecustomize = self.site / "sitecustomize.py"
197+
198+
# Ensure the site directory exists before writing files
199+
sitecustomize.parent.mkdir(parents=True, exist_ok=True)
200+
197201
sitecustomize.write_text(contents)
202+
203+
# Ubuntu 24.04 compatibility: Also create a .pth file that imports our customizations
204+
# This ensures our customizations run even if system sitecustomize is loaded first
205+
if self._sitecustomize is not None:
206+
# Create a separate module for our customizations
207+
customizations_module = self.site / "_venv_customizations.py"
208+
customizations_module.write_text(self._sitecustomize)
209+
210+
# Create a .pth file that imports this module
211+
pth_file = self.site / "venv_customizations.pth"
212+
pth_file.write_text("import _venv_customizations")
213+
198214
# Make sure bytecode is up-to-date too.
199215
assert compileall.compile_file(str(sitecustomize), quiet=1, force=True)
200216

0 commit comments

Comments
 (0)