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

Split logic into DynamicRemoteOptions.from_option into different code paths #16172

Merged
merged 6 commits into from
Jul 22, 2022

Conversation

asherf
Copy link
Member

@asherf asherf commented Jul 13, 2022

This duplicated some code (extracting options and passing them DynamicRemoteOptions) but I think having 3 code paths for the different use cases justifies that and makes this code more readable and hence more maintainable over time.

context for this change: I am planning to add entry point support for the auth plugin so the user doesn't have to specify the plugin path.
This will require some changes to the logic here and having a function that deals with loading the plugin (not mixed with the other code paths) will make it simpler and easier to grok.

not adding a label for now in order to prevent CI from running. will do that after the two PRs this change is on top of lands.

… paths

Granted, this duplicated some code (extracting options and passing them DynamicRemoteOptions) but I think having 3 code paths for the different use cases justifies that and makes this code more readable and hence more maintainable over time.
@asherf asherf added the category:internal CI, fixes for not-yet-released features, etc. label Jul 18, 2022
@asherf asherf marked this pull request as ready for review July 18, 2022 21:31
oauth_token = (
Path(bootstrap_options.remote_oauth_bearer_token_path).resolve().read_text().strip()
)
if set(oauth_token).intersection({"\n", "\r"}):
Copy link
Contributor

Choose a reason for hiding this comment

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

When is there a need to check for '\r'? Why not just if "\n" in oauth_token?

Copy link
Member Author

Choose a reason for hiding this comment

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

idk. this code was like this before. I don't thins we need to change this particular check in this PR.
it was added here:
2a5346e#diff-db4651ae839e702898bac44a00db5fd93b21701f624f57479fb537d7bc55a6d1R111
so maybe @Eric-Arellano can provide some context on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it was added a long time ago from Daniel Wagner Hall. We should probably keep it.

src/python/pants/option/global_options.py Outdated Show resolved Hide resolved
src/python/pants/option/global_options.py Show resolved Hide resolved
src/python/pants/option/global_options.py Outdated Show resolved Hide resolved
src/python/pants/option/global_options.py Outdated Show resolved Hide resolved
token_header = {"authorization": f"Bearer {oauth_token}"}
execution_headers.update(token_header)
store_headers.update(token_header)
execution = cast(bool, bootstrap_options.remote_execution)
Copy link
Contributor

Choose a reason for hiding this comment

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

These casts are duplicative of the casts in the OAuth bearer token function. Maybe have a common function to extract to an intermediate dataclass?

Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned in the PR description, I think having some code duplication is ok.
it makes it easier to understand and maintain, the duplicated code is trivial.
I don't see a real benefit that we would get by introducing a data class to reduce the duplicated code.

Copy link
Member

@stuhood stuhood Jul 22, 2022

Choose a reason for hiding this comment

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

In general I'd agree with Tom, but I think that it's maybe not necessary here since we're constructing a dataclass which provides the type safety of not being able to forget an option.

@asherf
Copy link
Member Author

asherf commented Jul 22, 2022

Ping

token_header = {"authorization": f"Bearer {oauth_token}"}
execution_headers.update(token_header)
store_headers.update(token_header)
execution = cast(bool, bootstrap_options.remote_execution)
Copy link
Member

@stuhood stuhood Jul 22, 2022

Choose a reason for hiding this comment

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

In general I'd agree with Tom, but I think that it's maybe not necessary here since we're constructing a dataclass which provides the type safety of not being able to forget an option.

@stuhood stuhood merged commit d089127 into pantsbuild:main Jul 22, 2022
@asherf asherf deleted the jerry branch July 22, 2022 20:01
@stuhood stuhood mentioned this pull request Jul 22, 2022
jyggen pushed a commit to jyggen/pants that referenced this pull request Jul 27, 2022
… paths (pantsbuild#16172)

I am planning to [add entry point support for the auth plugin](pantsbuild#16212) so the user doesn't have to specify the plugin path. This will require some changes to the logic here and having a function that deals with loading the plugin (not mixed with the other code paths) will make it simpler and easier to grok.

This duplicated some code (extracting options and passing them DynamicRemoteOptions) but I think having 3 code paths for the different use cases justifies that and makes this code more readable and hence more maintainable over time.

[ci skip-build-wheels]
[ci skip-rust]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:internal CI, fixes for not-yet-released features, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants