@@ -45,6 +45,7 @@ struct PyCfg {
45
45
cfg : PathBuf ,
46
46
version_info : String ,
47
47
interpreter : InterpreterConfig ,
48
+ user_site : bool ,
48
49
}
49
50
50
51
fn parse_venv_cfg ( venv_root : & Path , cfg_path : & Path ) -> miette:: Result < PyCfg > {
@@ -53,6 +54,7 @@ fn parse_venv_cfg(venv_root: &Path, cfg_path: &Path) -> miette::Result<PyCfg> {
53
54
let mut version: Option < String > = None ;
54
55
let mut bazel_interpreter: Option < String > = None ;
55
56
let mut bazel_repo: Option < String > = None ;
57
+ let mut user_site: Option < bool > = None ;
56
58
57
59
// FIXME: Errors possible here?
58
60
let reader = io:: BufReader :: new ( file) ;
@@ -66,12 +68,15 @@ fn parse_venv_cfg(venv_root: &Path, cfg_path: &Path) -> miette::Result<PyCfg> {
66
68
"version_info" => {
67
69
version = Some ( value. to_string ( ) ) ;
68
70
}
69
- "aspect_runfiles_interpreter " => {
71
+ "aspect-runfiles-interpreter " => {
70
72
bazel_interpreter = Some ( value. to_string ( ) ) ;
71
73
}
72
- "aspect_runfiles_repo " => {
74
+ "aspect-runfiles-repo " => {
73
75
bazel_repo = Some ( value. to_string ( ) ) ;
74
76
}
77
+ "aspect-include-user-site-packages" => {
78
+ user_site = Some ( value == "true" ) ;
79
+ }
75
80
// We don't care about other keys
76
81
& _ => { }
77
82
}
@@ -87,6 +92,7 @@ fn parse_venv_cfg(venv_root: &Path, cfg_path: &Path) -> miette::Result<PyCfg> {
87
92
rpath : rloc,
88
93
repo : repo,
89
94
} ,
95
+ user_site : user_site. expect ( "User site flag not set!" ) ,
90
96
} ) ,
91
97
// FIXME: Kinda useless copy in this case
92
98
( Some ( version) , None , None ) => Ok ( PyCfg {
@@ -96,6 +102,7 @@ fn parse_venv_cfg(venv_root: &Path, cfg_path: &Path) -> miette::Result<PyCfg> {
96
102
interpreter : InterpreterConfig :: External {
97
103
version : parse_version_info ( & version) . unwrap ( ) ,
98
104
} ,
105
+ user_site : user_site. expect ( "User site flag not set!" ) ,
99
106
} ) ,
100
107
( None , _, _) => Err ( miette ! (
101
108
"Invalid pyvenv.cfg file! no interpreter version specified!"
@@ -230,6 +237,12 @@ fn main() -> miette::Result<()> {
230
237
// Set the executable pointer for MacOS, but we do it consistently
231
238
cmd. env ( "PYTHONEXECUTABLE" , & venv_interpreter) ;
232
239
240
+ // Similar to `-s` but this avoids us having to muck with the argv in ways
241
+ // that could be visible to the called program.
242
+ if !venv_config. user_site {
243
+ cmd. env ( "PYTHONNOUSERSITE" , "1" ) ;
244
+ }
245
+
233
246
// Set the interpreter home to the resolved install base. This works around
234
247
// the home = property in the pyvenv.cfg being wrong because we don't
235
248
// (currently) have a good way to map the interpreter rlocation to a
0 commit comments