-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Require explicit environment usage #11641
Conversation
[ci skip-rust] [ci skip-build-wheels]
…ronment or a new filtered Environment type. [ci skip-build-wheels] [ci skip-rust]
[ci skip-build-wheels]
d6286eb
to
130b280
Compare
Commits are useful to review independently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commits are useful to review independently.
I'm hoping to save you typing. I think its safe to assume any PR initially posted with multiple commits has this true. If not, it was a sloppy post.
@rule | ||
async def complete_environment(session_values: SessionValues) -> CompleteEnvironment: | ||
return session_values[CompleteEnvironment] | ||
|
||
|
||
@rule | ||
async def environment_subset( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a non async function which begs the question of why not just a utility. Are you making room here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point: can drop the async
. But the reason to expose this as a @rule
is that we want to discourage direct access to the CompleteEnvironment
and expose an API that encourages requesting a filtered copy, because it should allow @rules
to be cleaned with early-cutoff in more cases. When a @rule
requests the entire environment, it will be invalidated for any environment change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you s/encourage/force/ by just changing the relevant Process field type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly...? I think that a majority of users of Process
right now are constructing an environment for the process by hand, and only some cases are pulling it in from the outside world. Most users of InteractiveProcess
will use the CompleteEnvironment
, but not all, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks great.
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
…ronment as deprecated. [ci skip-rust] [ci skip-build-wheels]
[ci skip-rust] [ci skip-build-wheels]
1a08dba
to
79b8ae0
Compare
…nvironment usage to unblock pantsbuild#11641. # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
…caching (#11678) ### Problem #11641 changed how `ExecutionOptions` are computed for the "bootstrap" `Scheduler` that is used for plugin resolution (in order to allow any local-affecting options to still be used, while only disabling remote execution). But the `local_only` flag was sloppily applied, and did not affect the boolean flags that actually enable or disable remote caching and execution. ### Solution Apply the `ExecutionOptions.from_options(local_only)` flag more thoroughly, so that both caching and execution are disabled (in addition to skipping the auth plugin). ### Result Repositories that use auth plugins and remote execution will not experience errors during plugin bootstrapping. [ci skip-build-wheels] [ci skip-rust]
) Since pantsbuild#11641, `sys.argv` has not been the right way to get the args for a particular run of pants. Explicitly pass in the args via the `OptionsBootstrapper`, and fix the test (which was actually testing its _own_ `sys.argv`). Fixes pantsbuild#11930. [ci skip-rust] [ci skip-build-wheels]
Problem
In order to allow concurrent runs of Pants in #11639 (part of #7654), all global mutable singletons must be either 1) thread-local, 2) replaced with explicitly passed values.
os.environ
andsys.argv
are two of the last cases we're concerned with.Solution
Although we could hypothetically redefine
os.environ
andos.getenv
as thread-local, they seem to be a better fit to be explicitly passed. So this change:PantsEnvironment
toCompleteEnvironment
Environment
andEnvironmentRequest
, which filter theCompleteEnvironment
to a smaller subset, and should be used more frequently by@rules
.os.environ
usage in thePythonSetup
subsystem by explicitly selecting interpreter-selection env vars (HOME
/PATH
/PYENV_ROOT
)Finally, we empty the environment for
pantsd
runs to enforce explicit usage ofCompleteEnvironment
/Environment
.Result
The last (?) global mutable variable blocking #7654 is removed.
[ci skip-build-wheels]