Skip to content

Commit

Permalink
PR feedback + fix stuff
Browse files Browse the repository at this point in the history
[ci skip-build-wheels]
  • Loading branch information
gshuflin committed Sep 22, 2020
1 parent 135dbe2 commit de715e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/python/pants/option/options.py
Expand Up @@ -68,11 +68,11 @@ class Options:
# This is a class-wide toggle for whether Python warnings (using the warnings module) should
# be emitted during the options-parsing process. We want to initially set this to `True` and
# then set it to `False` after we have done the initial options parsing.
suppress_warnings = True
_suppress_warnings = True

@classmethod
def toggle_option_warning_suppression(cls, toggle: bool) -> None:
cls.suppress_warnings = toggle
cls._suppress_warnings = toggle

class FrozenOptionsError(Exception):
"""Options are frozen and can't be mutated."""
Expand Down Expand Up @@ -448,7 +448,7 @@ def for_scope(
namespace=values_builder,
get_all_scoped_flag_names=lambda: self._all_scoped_flag_names_for_fuzzy_matching,
passthrough_args=self._passthru,
suppress_warnings=self.suppress_warnings,
suppress_warnings=self._suppress_warnings,
)

values = self._parser_hierarchy.get_parser_by_scope(scope).parse_args(parse_args_request)
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/option/options_test.py
Expand Up @@ -1138,6 +1138,7 @@ def assert_deprecation_triggered(
env: Optional[Dict[str, str]] = None,
config: Optional[Dict[str, Dict[str, str]]] = None,
) -> None:
Options.toggle_option_warning_suppression(False)
warnings.simplefilter("always")
with pytest.warns(DeprecationWarning) as record:
options = self._parse(flags=flags, env=env, config=config)
Expand Down Expand Up @@ -1211,6 +1212,7 @@ def assert_deprecation_triggered(

@unittest.mock.patch("pants.base.deprecated.PANTS_SEMVER", Version(_FAKE_CUR_VERSION))
def test_delayed_deprecated_option(self) -> None:
Options.toggle_option_warning_suppression(False)
warnings.simplefilter("always")
with pytest.warns(None) as record:
delayed_deprecation_option_value = (
Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/option/parser.py
Expand Up @@ -345,9 +345,10 @@ def add_flag_val(v: Optional[Union[int, float, bool, str]]) -> None:
f"Error computing value for {args_str} in {self._scope_str()} (may also be from PANTS_* environment variables).\nCaused by:\n{traceback.format_exc()}"
)

# If the option is explicitly given, check deprecation and mutual exclusion.
# If the option is explicitly given, check deprecation (unless suppressed) and mutual exclusion.

print_warning = parse_args_request.suppress_warnings is False
if val.rank > Rank.HARDCODED:
print_warning = not parse_args_request.suppress_warnings
self._check_deprecated(dest, kwargs, print_warning=print_warning)

mutex_dest = kwargs.get("mutually_exclusive_group")
Expand Down

0 comments on commit de715e1

Please sign in to comment.