Skip to content

Commit ca9583e

Browse files
LukaJuriciccottsay
andauthored
Disable sitecustomize paths if in virtual env (#623)
The purpose of the sitecustomize here is to make setuptools install stuff to our prefix instead of the global prefix, and to appear enough like a virtual environment that platform-specific patches to sysconfig don't interfere with that effort. It isn't inconceivable that there may be subprocesses involved in the build, and we want any installation happening in those subprocesses to also get the redirect, and that currently works as expected as long as the sitecustomize directory remains on PYTHONPATH somewhere. However, if some subprocess is also modifying sys.prefix, as would be the case if a subprocess was using a new virtual environment, we don't want to override those changes. Since we know what sys.prefix was when colcon was invoked, we can just check to see if it changed. Co-authored-by: Luka Juricic <[email protected]> Co-authored-by: Scott K Logan <[email protected]>
1 parent 0539c39 commit ca9583e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

colcon_core/task/python/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ async def build(self, *, additional_hooks=None): # noqa: D102
7070
Path(__file__).parent / 'template' / 'sitecustomize.py.em',
7171
prefix_override / 'sitecustomize.py',
7272
{
73+
'current_prefix': sys.prefix,
7374
'site_prefix': args.install_base,
7475
})
7576

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import sys
2-
sys.real_prefix = sys.prefix
3-
sys.prefix = sys.exec_prefix = @repr(site_prefix)
2+
if sys.prefix == @repr(current_prefix):
3+
sys.real_prefix = sys.prefix
4+
sys.prefix = sys.exec_prefix = @repr(site_prefix)

0 commit comments

Comments
 (0)