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 the mypy-protobuf interpreter constraint. #11695

Merged
merged 2 commits into from Mar 15, 2021

Conversation

jsirois
Copy link
Member

@jsirois jsirois commented Mar 14, 2021

Also add an option to allow a user to adjust the interpreter constraint
when adjusting the mypy-protobuf plugin version as they can with other
python tools.

Fixes #11565

[ci skip-rust]
[ci skip-build-wheels]

Also add an option to allow a user to adjust the interpreter constraint
when adjusting the mypy-protobuf plugin version as they can with other
python tools.

Fixes pantsbuild#11565

[ci skip-rust]
[ci skip-build-wheels]
@jsirois jsirois mentioned this pull request Mar 14, 2021
jsirois referenced this pull request Mar 14, 2021
This brings in new features, including the option to generating gRPC type stubs.
# 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]
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

# the deprecated option in flag and environment variable namespaces; i.e.: both
# --python-protobuf-mypy-plugin-version and PANTS_PYTHON_PROTOBUF_MYPY_PLUGIN_VERSION
# will continue to work."
deprecated_conditional(
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I'm not sure that I fully understand how this deprecation works, but given that the plugin was added recently, I won't investigate too closely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's tricky enough that I went through the steps to test all this. The only deprecated thing is the config syntax and this triggers only for that by design.

Copy link
Contributor

@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.

Thank you for tackling this.

Comment on lines -41 to +59
def version(self) -> str:
def requirement(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Good change.

Comment on lines +87 to +89
predicate=lambda: (
python_protobuf_subsystem.options.get_rank(deprecated_key) == Rank.CONFIG
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically we use not subsystem.options.is_default("foo") - is there a particular reason to only check for config?

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better, you can deprecate the original --mypy-plugin-version option, right? That is less code, makes the deprecation be eager at Pants init, and updates ./pants help + the site to do the right thing.

Copy link
Member Author

@jsirois jsirois Mar 15, 2021

Choose a reason for hiding this comment

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

Config is the only deprecated thing. The flag and env var forms do not change as the comment tries to make clear. As such, to deprecate any non-config usage would be to complain at a user for doing nothing wrong.

return cast(str, self.options.mypy_plugin_version)

class PythonProtobufMypyPlugin(PythonToolRequirementsBase):
options_scope = PythonProtobufSubsystem.subscope("mypy-plugin")
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI this is the first usage of subscopes in Pants 2.x. I think we had some tentative discussion a few months back on whether we want to have this or not, and what the semantics should be. Cc @stuhood, you had some thoughts iirc.

I think this is fine, but want to draw attention to this setting up a new precedent.

Copy link
Sponsor Member

@stuhood stuhood Mar 15, 2021

Choose a reason for hiding this comment

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

I think that this usecase is roughly in the spirit of how we would want subscopes to be used. But honestly, I'm mostly surprised that it works.

@jsirois: The primary difference to watch out for is that in the past, subscopes were primarily generated dynamically to add a common/reusable Subsystem to a scope. Because of that, we have inheritance/recursion of options applied to scopes. For example: with a scope my-jvm-tool.common-jvm-config, setting an option in scope my-jvm-tool.common-jvm-config affects only that instance of the subsystem. But setting that same option in common-jvm-config would affect all subscopes like *.common-jvm-config.

Copy link
Member Author

@jsirois jsirois Mar 15, 2021

Choose a reason for hiding this comment

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

Yeah - I wrote that bit of Subsystems IIRC. This does not use that though, it just uses the subscope namespace as a trick to ensure shadowing as opposed to setting the subsystem options scope to python-protobuf-mypy-plugin which I also could have done. The difference would have merely been s/./-/ in the pants.toml config key name (i.e.: s/[python-protobuf.mypy-plugin]/[python-protobuf-mypy-plugin]/. The s/./-/ does not affect either the flag name or the env var name.

@@ -43,7 +46,6 @@ def register_options(cls, register):
register(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on moving the above --mypy-plugin bool option to the new subsystem? I'm not sure which place make more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it makes more sense here. Do you want extra feature foo? Great, I'll load a subsystem for that to get the configuration for the extra feature. The use-it-ness is a property of the python-protobuf configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds sensible to me. Thanks!

@jsirois jsirois merged commit d902422 into pantsbuild:master Mar 15, 2021
@jsirois jsirois deleted the issues/11565 branch March 15, 2021 18:59
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.

Fix PythonProtobufSubsystem mypy-protobuf interpreter selection.
3 participants