-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global option
process_extra_env
(#6)
Upstream pr pantsbuild/pants#21501
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
diff --git a/src/python/pants/engine/intrinsics.py b/src/python/pants/engine/intrinsics.py | ||
index b99e1a682a..1114d86de4 100644 | ||
--- a/src/python/pants/engine/intrinsics.py | ||
+++ b/src/python/pants/engine/intrinsics.py | ||
@@ -97,15 +97,19 @@ async def add_prefix_request_to_digest(add_prefix: AddPrefix) -> Digest: | ||
return await native_engine.add_prefix_request_to_digest(add_prefix) | ||
|
||
|
||
+import dataclasses | ||
+from pants.option.global_options import GlobalOptions | ||
@rule | ||
async def process_request_to_process_result( | ||
- process: Process, process_execution_environment: ProcessExecutionEnvironment | ||
+ process: Process, | ||
+ process_execution_environment: ProcessExecutionEnvironment, | ||
+ options: GlobalOptions, | ||
) -> FallibleProcessResult: | ||
+ process = dataclasses.replace(process, env={**process.env, **options.process_extra_env}) | ||
return await native_engine.process_request_to_process_result( | ||
process, process_execution_environment | ||
) | ||
|
||
- | ||
@rule | ||
async def digest_subset_to_digest(digest_subset: DigestSubset) -> Digest: | ||
return await native_engine.digest_subset_to_digest(digest_subset) | ||
diff --git a/src/python/pants/option/global_options.py b/src/python/pants/option/global_options.py | ||
index 364d4366a0..a1e279e2e6 100644 | ||
--- a/src/python/pants/option/global_options.py | ||
+++ b/src/python/pants/option/global_options.py | ||
@@ -1964,6 +1964,15 @@ class GlobalOptions(BootstrapOptions, Subsystem): | ||
default=[], | ||
) | ||
|
||
+ process_extra_env = DictOption[str]( | ||
+ advanced=True, | ||
+ help=softwrap( | ||
+ """ | ||
+ Extra environment variables for every Process call. | ||
+ """ | ||
+ ) | ||
+ ) | ||
+ | ||
@classmethod | ||
def validate_instance(cls, opts): | ||
"""Validates an instance of global options for cases that are not prohibited via |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
diff --git a/src/python/pants/engine/intrinsics.py b/src/python/pants/engine/intrinsics.py | ||
index 5695a3baf..2d14b9314 100644 | ||
--- a/src/python/pants/engine/intrinsics.py | ||
+++ b/src/python/pants/engine/intrinsics.py | ||
@@ -100,10 +100,15 @@ async def add_prefix(add_prefix: AddPrefix) -> Digest: | ||
return await native_engine.add_prefix(add_prefix) | ||
|
||
|
||
+import dataclasses | ||
+from pants.option.global_options import GlobalOptions | ||
@rule | ||
async def execute_process( | ||
- process: Process, process_execution_environment: ProcessExecutionEnvironment | ||
+ process: Process, | ||
+ process_execution_environment: ProcessExecutionEnvironment, | ||
+ options: GlobalOptions, | ||
) -> FallibleProcessResult: | ||
+ process = dataclasses.replace(process, env={**process.env, **options.process_extra_env}) | ||
return await native_engine.execute_process(process, process_execution_environment) | ||
|
||
|
||
diff --git a/src/python/pants/option/global_options.py b/src/python/pants/option/global_options.py | ||
index 6ae7843a9..3e397534b 100644 | ||
--- a/src/python/pants/option/global_options.py | ||
+++ b/src/python/pants/option/global_options.py | ||
@@ -1998,6 +1998,15 @@ class GlobalOptions(BootstrapOptions, Subsystem): | ||
default=[], | ||
) | ||
|
||
+ process_extra_env = DictOption[str]( | ||
+ advanced=True, | ||
+ help=softwrap( | ||
+ """ | ||
+ Extra environment variables for every Process call. | ||
+ """ | ||
+ ) | ||
+ ) | ||
+ | ||
@classmethod | ||
def validate_instance(cls, opts): | ||
"""Validates an instance of global options for cases that are not prohibited via |