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

Validate that option scopes and target aliases don't collide. #11004

Merged
merged 4 commits into from
Oct 21, 2020

Conversation

benjyw
Copy link
Sponsor Contributor

@benjyw benjyw commented Oct 21, 2020

Also reserves some names that cannot be used as scopes or aliases
('global', 'targets', 'goals') so that ./pants help <name> is
unambiguous.

Works towards addressing #10999.

Also removes some cruft from test_extension_loader.py.

[ci skip-rust]

[ci skip-build-wheels]

Also reserves some names that cannot be used as scopes or aliases
('global', 'targets', 'goals') so that `./pants help <name>` is
unambiguous.

Works towards addressing pantsbuild#10999.

Also removes some cruft from test_extension_loader.py.

[ci skip-rust]

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

benjyw commented Oct 21, 2020

Note, also tested manually by changing names of various scopes to see what happens.

@dataclass(frozen=True)
class BuildConfiguration:
"""Stores the types and helper functions exposed to BUILD files."""

registered_aliases: BuildFileAliases
optionables: FrozenOrderedSet[Optionable]
optionables: FrozenOrderedSet[Type[Optionable]]
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Note that this was always wrong.

@coveralls
Copy link

coveralls commented Oct 21, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 733fbd0 on benjyw:validate_names into 92a2087 on pantsbuild:master.

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.

Thanks! Everything looks great modulo one comment.

With that comment implemented, I think you will need to rename #10999 (comment). I encourage doing that as a precursor PR for the sake of the changelog. This PR is "internal only" so left off, and we want a dedicated entry for "Deprecated scope Foo in favor of Bar"

src/python/pants/build_graph/build_configuration.py Outdated Show resolved Hide resolved
"""Return all optionables in the system: global and those registered via rule usage."""
return _GLOBAL_SUBSYSTEMS | self.optionables

def __post_init__(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will catch collisions between the subsystem pex-binary and the target type pex_binary. As discussed, that's subtle and I think we do want to error here.

To fix, I think for subsystems you can add both my-scope and my_scope to the defaultdict? We know target types can only use _ due to Python restrictions.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Was going to do that in a followup, along with actually allowing the normalized form in config files, but yeah I can add just the check here now.

@benjyw
Copy link
Sponsor Contributor Author

benjyw commented Oct 21, 2020

Thanks! Everything looks great modulo one comment.

With that comment implemented, I think you will need to rename #10999 (comment). I encourage doing that as a precursor PR for the sake of the changelog. This PR is "internal only" so left off, and we want a dedicated entry for "Deprecated scope Foo in favor of Bar"

I don't think this is internal only - it has external effect. If someone happened to have a custom target type or option with a colliding name, they will now get an error.

@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Oct 21, 2020

I don't think this is internal only

True, but I think that would be "Plugin API Changes", vs. "User API changes" for the deprecations.

# 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]
[ci skip-rust]

[ci skip-build-wheels]
# 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
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.

Awesome! Thanks!

@benjyw benjyw merged commit 2895745 into pantsbuild:master Oct 21, 2020
@benjyw benjyw deleted the validate_names branch October 21, 2020 20:46
Eric-Arellano pushed a commit to Eric-Arellano/pants that referenced this pull request Oct 22, 2020
…uild#11004)

Also reserves some names that cannot be used as scopes or aliases
('global', 'targets', 'goals') so that `./pants help <name>` is
unambiguous.

Works towards addressing pantsbuild#10999.

Also removes some cruft from test_extension_loader.py.
Eric-Arellano added a commit that referenced this pull request Oct 22, 2020
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.

3 participants