Skip to content

Commit

Permalink
Deprecate [validate].detail_level in favor of `[sourcefile-validati…
Browse files Browse the repository at this point in the history
…on].detail_level` (#14103)

Prework for #14102. The `GoalSubsystem` will be going away so the option should live on the relevant subsystem instead.

I'm not sure if `sourcefile-validation` is the best options scope for #14102, but I'm not sure what else we would call it.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Jan 7, 2022
1 parent ba3ab0c commit 1027041
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/python/pants/backend/project_info/source_file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from enum import Enum
from typing import Any, cast

from pants.base.deprecated import resolve_conflicting_options
from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE
from pants.engine.collection import Collection
from pants.engine.console import Console
Expand Down Expand Up @@ -52,12 +53,12 @@ def register_options(cls, register):
type=DetailLevel,
default=DetailLevel.nonmatching,
help="How much detail to emit to the console.",
removal_version="2.11.0.dev0",
removal_hint=(
"Use `[sourcefile-validation].detail_level` instead, which behaves the same."
),
)

@property
def detail_level(self) -> DetailLevel:
return cast(DetailLevel, self.options.detail_level)


class Validate(Goal):
subsystem_cls = ValidateSubsystem
Expand Down Expand Up @@ -134,6 +135,12 @@ def register_options(cls, register):
)
super().register_options(register)
register("--config", type=dict, fromfile=True, help=schema_help)
register(
"--detail-level",
type=DetailLevel,
default=DetailLevel.nonmatching,
help="How much detail to include in the result.",
)

@memoized_method
def get_multi_matcher(self) -> MultiMatcher | None:
Expand All @@ -143,6 +150,19 @@ def get_multi_matcher(self) -> MultiMatcher | None:
else None
)

def detail_level(self, validate_subsystem: ValidateSubsystem) -> DetailLevel:
return cast(
DetailLevel,
resolve_conflicting_options(
old_option="detail_level",
new_option="detail_level",
old_container=validate_subsystem.options,
new_container=self.options,
old_scope=validate_subsystem.name,
new_scope=self.options_scope,
),
)


@dataclass(frozen=True)
class RegexMatchResult:
Expand Down Expand Up @@ -305,7 +325,7 @@ async def validate(
for file_content in sorted(digest_contents, key=lambda fc: fc.path)
)

detail_level = validate_subsystem.detail_level
detail_level = source_file_validation.detail_level(validate_subsystem)
num_matched_all = 0
num_nonmatched_some = 0
for rmr in regex_match_results:
Expand Down

0 comments on commit 1027041

Please sign in to comment.