File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ def _py_venv_base_impl(ctx):
133
133
py_toolchain .interpreter_version_info .major ,
134
134
py_toolchain .interpreter_version_info .minor ,
135
135
),
136
+ "--include-system-site-packages=" + ({
137
+ True : "true" ,
138
+ False : "false"
139
+ }[ctx .attr .include_system_site_packages ]),
136
140
] + (["--debug" ] if ctx .attr .debug else []),
137
141
inputs = rfs .merge_all ([
138
142
ctx .runfiles (files = [
@@ -294,6 +298,24 @@ A collision can occur when multiple packages providing the same file are install
294
298
"debug" : attr .bool (
295
299
default = False ,
296
300
),
301
+ "include_system_site_packages" : attr .bool (
302
+ default = True ,
303
+ doc = """`pyvenv.cfg` feature flag for the `include-system-site-packages` key.
304
+
305
+ When `True`, the user's site directory AND the interpreter's site directory will
306
+ be included into the runtime pythonpath.
307
+
308
+ When `False`, only the virtualenv's site directory and the interpreter's core
309
+ libraries will be included into the runtime pythonpath.
310
+
311
+ `False` is obviously preferable as it increases hermeticity, but the choice of
312
+ `False` cases for instance a `pip` or `setuptools` bundled into the interpreter
313
+ to be unusable. Many libraries assume these packages will always be available
314
+ and may not reliably declare their dependencies such that Bazel will satisfy
315
+ them, so choosing isolation could expose packaging errors.
316
+
317
+ """
318
+ ),
297
319
})
298
320
299
321
_attrs .update (** _py_library .attrs )
Original file line number Diff line number Diff line change 1
1
home = ./bin/python3
2
2
implementation = CPython
3
3
version_info = {{MAJOR}}.{{MINOR}}.{{PATCH}}
4
- include-system-site-packages = true
4
+ include-system-site-packages = {{INCLUDE_SYSTEM_SITE}}
5
5
relocatable = true
6
6
{{INTERPRETER}}
Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ pub fn create_empty_venv<'a>(
210
210
env_file : & Option < PathBuf > ,
211
211
venv_shim : & Option < PathBuf > ,
212
212
debug : bool ,
213
+ include_system_site_packages : bool ,
213
214
) -> miette:: Result < Virtualenv > {
214
215
let build_dir = current_dir ( ) . into_diagnostic ( ) ?;
215
216
let home_dir = & build_dir. join ( location. to_path_buf ( ) ) ;
@@ -265,7 +266,11 @@ aspect_runfiles_repo = {1}
265
266
. replace ( "{{MAJOR}}" , & venv. version_info . major . to_string ( ) )
266
267
. replace ( "{{MINOR}}" , & venv. version_info . minor . to_string ( ) )
267
268
. replace ( "{{PATCH}}" , & venv. version_info . patch . to_string ( ) )
268
- . replace ( "{{INTERPRETER}}" , interpreter_cfg_snippet) ,
269
+ . replace ( "{{INTERPRETER}}" , interpreter_cfg_snippet)
270
+ . replace (
271
+ "{{INCLUDE_SYSTEM_SITE}}" ,
272
+ & include_system_site_packages. to_string ( ) ,
273
+ ) ,
269
274
)
270
275
. into_diagnostic ( ) ?;
271
276
Original file line number Diff line number Diff line change 1
1
use std:: path:: PathBuf ;
2
2
3
+ use clap:: ArgAction ;
3
4
use clap:: Parser ;
4
5
use miette:: miette;
5
6
use miette:: Context ;
@@ -90,6 +91,16 @@ struct VenvArgs {
90
91
91
92
#[ arg( long, default_value_t = false ) ]
92
93
debug : bool ,
94
+
95
+ #[ clap(
96
+ long,
97
+ default_missing_value( "true" ) ,
98
+ default_value( "true" ) ,
99
+ num_args( 0 ..=1 ) ,
100
+ require_equals( true ) ,
101
+ action = ArgAction :: Set ,
102
+ ) ]
103
+ include_system_site_packages : bool ,
93
104
}
94
105
95
106
fn venv_cmd_handler ( args : VenvArgs ) -> miette:: Result < ( ) > {
@@ -119,6 +130,7 @@ fn venv_cmd_handler(args: VenvArgs) -> miette::Result<()> {
119
130
& args. env_file ,
120
131
& args. venv_shim ,
121
132
args. debug ,
133
+ args. include_system_site_packages ,
122
134
) ?;
123
135
124
136
py:: venv:: populate_venv_with_copies (
@@ -147,6 +159,7 @@ fn venv_cmd_handler(args: VenvArgs) -> miette::Result<()> {
147
159
& args. env_file ,
148
160
& args. venv_shim ,
149
161
args. debug ,
162
+ args. include_system_site_packages ,
150
163
) ?;
151
164
152
165
py:: venv:: populate_venv_with_pth (
You can’t perform that action at this time.
0 commit comments