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

Move native options parsing out of the legacy Parser #21652

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

benjyw
Copy link
Contributor

@benjyw benjyw commented Nov 15, 2024

The Parser class had two jobs:

  • A repository of option registrations
  • Actual option parsing

This change removes the final vestiges of the second, by
inlining them in options.py.

A future change will rename Parser to, say, Registrar, as
befits its now single remaining role.

@benjyw benjyw added the category:internal CI, fixes for not-yet-released features, etc. label Nov 15, 2024
@benjyw benjyw requested review from huonw and tdyas November 15, 2024 23:19
@@ -410,8 +416,47 @@ def for_scope(
:return: An OptionValueContainer representing the option values for the given scope.
:raises pants.option.errors.ConfigValidationError: if the scope is unknown.
"""
builder = OptionValueContainerBuilder()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all moved verbatim from parser.py.

)
explicitly_set = rank > Rank.HARDCODED

# If we explicitly set a deprecated but not-yet-expired option, warn about it.
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 one change is that we used to check deprecations twice, once at registration time (but only to catch expired deprecations) and once at parse time. Now we do both in a single check, here, at parse time.

with pytest.raises(CodeRemovedError):
create_options([GLOBAL_SCOPE], register, [])
opts.for_scope(scope=GLOBAL_SCOPE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

creating options doesn't now trigger the expired deprecation check, we must parse.

@@ -95,7 +91,7 @@ def _invert(cls, s: bool | str | None) -> bool | None:
def __init__(self, scope: str) -> None:
"""Create a Parser instance.

:param scope_info: the scope this parser acts for.
:param scope: the scope this parser acts for.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a leftover docstring error

@benjyw benjyw merged commit 889eed4 into pantsbuild:main Nov 16, 2024
24 checks passed
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.

2 participants