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: ignore_root_user_error should be taken from root module only #1662

Merged
merged 10 commits into from
Jan 14, 2024

Conversation

shabanzd
Copy link
Contributor

@shabanzd shabanzd commented Jan 2, 2024

Only the root module should be able to decide ignore_root_user_error. Modules being depended upon don't know the final environment, so they aren't in the right position to know or decide what the correct setting is. This PR implements a solution to take the ignore_root_user_error value from the root module only.

Fixes #1658

@shabanzd shabanzd requested a review from rickeylev as a code owner January 2, 2024 17:01
Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

python/private/bzlmod/python.bzl Outdated Show resolved Hide resolved
@shabanzd shabanzd force-pushed the ignore_root_user_error_fix branch 4 times, most recently from 2fbb06b to a73c85f Compare January 4, 2024 22:31
@rickeylev
Copy link
Collaborator

Also, remember the root might might not explicitly setup any python toolchains; it might only be getting one because of some transitive module that needs python.

And yes, only the root module should be able to set ignore_root_user_error. A module being used as a library doesn't know what the final runtime environment is, so it can't know what the correct decision is.

@shabanzd shabanzd force-pushed the ignore_root_user_error_fix branch from a73c85f to 9783eaa Compare January 5, 2024 13:45
@shabanzd shabanzd requested a review from aignas January 7, 2024 16:55
Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

LGTM, but it needs a CHANGELOG snippet and it wouldbe great to have the PR description to be a nice summary of the change as well as it will be used as a commit message when the PR gets merged.

@shabanzd shabanzd force-pushed the ignore_root_user_error_fix branch from 4d55aef to 4015895 Compare January 8, 2024 12:30
@aignas
Copy link
Collaborator

aignas commented Jan 9, 2024

@shabanzd could you think of a way to add an integration test for this? The main branch has support for bazel-in-bazel integration tests now and you could add one in tests/integration that would exercise the modified code.

@rickeylev
Copy link
Collaborator

I originally requested tests when Ignas asked me about this PR, but I'm not so sure we should block on that now. The only idea I have for testing this is to add some print statements and check their output in the integration test. The prints would be guarded by an environment variable. However, doing that requires setting up a new test runner for the integration tests (one that can capture output and assert on it), which is maybe a bit too much to ask a new contributor in this PR.

Any alternative testing ideas that might be easier?

@ziad-fernride
Copy link

I would agree with @aignas that maybe the simplest way would be to have bazel-in-bazel integration tests with different scenarios and check for failures/successes based on the scenario ?

@rickeylev
Copy link
Collaborator

Ah, that gives me an idea: write an extra file somewhere with some info about what the extension did. Guard this behind an environment variable. Then we can write a test inside the integration test that reads that file and verifies its content. Maybe have the python repository repo rule write out what its settings were? Then it should be easy to use_repo() it and locate the file within it.

Copy link
Collaborator

@rickeylev rickeylev left a comment

Choose a reason for hiding this comment

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

I added an integration test to verify behavior. It works as I described last: the extension checks an environment variable and writes a file with some debug info. A test reads it to verify what happened. Overall it works pretty well and isn't very invasive; we can probably use this same technique to test other subtle cases with the bzlmod extension code.

@rickeylev rickeylev added this pull request to the merge queue Jan 14, 2024
@shabanzd
Copy link
Contributor Author

Sorry was offline since Thursday, thanks for taking care of the testing @rickeylev 🙏🏼🙏🏼

Merged via the queue into bazelbuild:main with commit 8ecad9d Jan 14, 2024
4 checks passed
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.

setting ignore_root_user_error to True in root module is not enough to avoid the root user error (bzlmod)
4 participants