Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global option process_extra_env for every Process call #21501

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/notes/2.24.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ We offer [formal sponsorship tiers for companies](https://www.pantsbuild.org/spo

* Fixed bug where `pants peek --include-additional-info` was not actually displaying the additional info ([#21399](https://github.com/pantsbuild/pants/pull/21399)).

* Fixed the `[subprocess-environment].env_vars` option to set arbitrary env variables for every pants Process call.

### New Options System

This release switches the Pants [options system](https://www.pantsbuild.org/2.22/docs/using-pants/key-concepts/options) to use the new "native" implementation written in Rust first introduced in the 2.22.x series.
Expand Down
18 changes: 17 additions & 1 deletion src/python/pants/engine/intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import annotations
from pants.core.util_rules.subprocess_environment import SubprocessEnvironment, SubprocessEnvironmentVars
from pants.core.util_rules import subprocess_environment

import dataclasses
import itertools
import logging

from pants.engine.environment import EnvironmentName
Expand Down Expand Up @@ -39,7 +43,11 @@
ProcessExecutionEnvironment,
)
from pants.engine.rules import _uncacheable_rule, collect_rules, implicitly, rule
from pants.option.global_options import GlobalOptions
from pants.util.docutil import git_url
from pants.util.frozendict import FrozenDict
from pants.engine.env_vars import EnvironmentVars, EnvironmentVarsRequest
from pants.engine.internals.selectors import Get


@rule
Expand Down Expand Up @@ -102,8 +110,15 @@ async def add_prefix(add_prefix: AddPrefix) -> Digest:

@rule
async def execute_process(
process: Process, process_execution_environment: ProcessExecutionEnvironment
process: Process,
process_execution_environment: ProcessExecutionEnvironment,
subproc_env: SubprocessEnvironment.EnvironmentAware,
) -> FallibleProcessResult:
names = subproc_env.env_vars_to_pass_to_subprocesses
if names:
env_vars = await Get(EnvironmentVars, EnvironmentVarsRequest(names))
items = itertools.chain(process.env.items(), env_vars.items())
process = dataclasses.replace(process, env=FrozenDict(items))
return await native_engine.execute_process(process, process_execution_environment)


Expand Down Expand Up @@ -207,4 +222,5 @@ async def path_metadata_request(request: PathMetadataRequest) -> PathMetadataRes
def rules():
return [
*collect_rules(),
*subprocess_environment.rules(),
]
Loading