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

Fix run, repl, and test --debug to have hermetic environments #10668

Merged
merged 4 commits into from Aug 23, 2020

Conversation

Eric-Arellano
Copy link
Contributor

Previously, InteractiveProcess used whatever the env was for the ./pants process. While this can be convenient, it is not consistent with the rest of Pants. For example, it was possible for a test to pass with test --debug but fail with test --no-debug, or vice versa, due to differences with the env.

This change reinforces the need for #10644, and for that to be ergonomic for users to set arbitrary env vars.

[ci skip-build-wheels]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
Copy link
Contributor Author

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR breaks test --open-coverage. Fixing now.

@@ -5,7 +5,7 @@
import logging
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are so that test --debug uses the same argv and env as the normal Process would be.

This rewrites it to use our new `BinaryPaths` abstraction to find the `open` program. It also fixes a cheat where we were using `Console` and `InteractiveRunner` outside of a goal rule.

# 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]
@Eric-Arellano
Copy link
Contributor Author

Okay, ready for review.

# 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]
@coveralls
Copy link

coveralls commented Aug 21, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling e5b4735 on Eric-Arellano:hermetic-ip into 8fcd228 on pantsbuild:master.

@Eric-Arellano Eric-Arellano merged commit aa6e1a4 into pantsbuild:master Aug 23, 2020
@Eric-Arellano Eric-Arellano deleted the hermetic-ip branch August 23, 2020 22:36
@stuhood
Copy link
Sponsor Member

stuhood commented Aug 24, 2020

While a hermetic environment makes sense for test, I don't think that it makes sense for run/repl... run in particular takes arguments, so it makes sense that it would also take env vars. And repl is purely for experimentation, and can't really be automated. But maybe #10644 will be sufficiently easy to use that this won't be an issue in practice.

benjyw added a commit to benjyw/pants that referenced this pull request Aug 24, 2020
…nments (pantsbuild#10668)"

This reverts commit aa6e1a4.

Unfortunately it caused the wheel-building CI shards to fail
in master.

[ci skip-build-wheels]
@benjyw
Copy link
Sponsor Contributor

benjyw commented Aug 24, 2020

Note: Reverted in #10688, until we can figure out why this broke the wheel building shards.

benjyw added a commit that referenced this pull request Aug 24, 2020
…nments (#10668)" (#10688)

This reverts commit aa6e1a4.

Unfortunately it caused the wheel-building CI shards to fail
in master.

[ci skip-build-wheels]
@Eric-Arellano
Copy link
Contributor Author

I don't have a strong opinion on run and repl. I suspect it should be hermetic for consistency with the rest of Pants, but I also understand Stu's rationale.

I do strongly believe that test --debug should behave identically to test, though.

If we have run and repl not be hermetic, but test --debug be, then I think we'll want to set a boolean parameter on InteractiveProcess called hermetic_env: bool, with a default of True. run.py and repl.py can turn off the hermetic env. Thoughts?

@benjyw
Copy link
Sponsor Contributor

benjyw commented Aug 28, 2020

I can see that the user might expect run and repl to see the calling env, so it shouldn't be hermetic. That doesn't seem controversial.

Not sure I agree that test --debug is different. I could go either way. It's really down to what users expect.

@Eric-Arellano
Copy link
Contributor Author

Not sure I agree that test --debug is different. I could go either way. It's really down to what users expect.

My argument with test --debug is that we should be consistent with test. It's confusing for something to pass with one, but not the other. Often, I'd expect a user to use test --debug when iterating; once they get it passing with test --debug, it would be frustrating for that to break when switching to `test.

Eric-Arellano added a commit that referenced this pull request Aug 29, 2020
…etic (#10701)

## Problem

See #10668 for the original implementation, which ended up getting reverted.

As pointed out there and in #10644, there's an argument to keeping `run` and `repl` non-hermetic, i.e. using the env for the parent `./pants` process. Neither of those goals are cached. REPL is designed for experimentation. Run's analog is `binary`; when producing a `binary` and then running it, the `binary` would end up having the env of the host platform, rather than what Pants sets.

However, we do want `test --debug` to be hermetic so that `test` and `test --debug` behave the same.

## Solution

Add the argument `hermetic_env: bool` to the `InteractiveProcess` constructor, which controls whether the env gets stripped or not. We default this to `True` as, generally, hermiticity is a good default.

`run.py` and `repl.py` ensure that `hermetic_env` is always set to False.

### Nuance: env var may be still be overridden

If the `InteractiveProcess` includes an env var that is already set in the parent process's env, then we will override the env var with Pants's value.

Tangibly, the Python implementations for `repl` and `run` will override the `$PATH` to whatever is set via `--pex-executable-search-paths`.

[ci skip-build-wheels]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants