diff --git a/.ruff.toml b/.ruff.toml index b13c86e4..13cbb685 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -1,10 +1,6 @@ extend = "pyproject.toml" lint.ignore = [ - # Pylint (PL) - # https://docs.astral.sh/ruff/rules/#pylint-pl - "PLW0603", # Using the global statement to update is discouraged. - # flake8-self (SLF) # https://docs.astral.sh/ruff/rules/#flake8-self-slf "SLF001", # Private member accessed. @@ -16,8 +12,3 @@ lint.ignore = [ # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann "ANN401", # Dynamically typed expressions (typing.Any). ] -"test_slice_lines.py" = [ - # eradicate (ERA) - # https://docs.astral.sh/ruff/rules/#eradicate-era - "ERA001", # Found commented-out code. -] diff --git a/pyproject.toml b/pyproject.toml index 054ea8d3..4758da25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -270,6 +270,11 @@ max-statements = 91 "ANN001", # Missing type annotation for function argument. "ANN201", # Missing return type annotation for public funciton. ] +# TODO @bjlittle: investigate behaviour of commented-out failing test +"tests/core/test_slice_lines.py" = [ + # https://docs.astral.sh/ruff/rules/#eradicate-era + "ERA001", # eradicate: Found commented-out code. +] [tool.ruff.lint.pydocstyle] diff --git a/src/geovista/cache/__init__.py b/src/geovista/cache/__init__.py index 4a8f4c2c..84a1cb01 100644 --- a/src/geovista/cache/__init__.py +++ b/src/geovista/cache/__init__.py @@ -148,7 +148,7 @@ def _downloader( return downloader(url, output_file, poocher, check_only=check_only) -def pooch_mute(silent: bool | None = True) -> None: +def pooch_mute(silent: bool | None = True) -> bool: """Control the :mod:`pooch` cache manager logger verbosity. Updates the status variable :data:`GEOVISTA_POOCH_MUTE`. @@ -159,16 +159,23 @@ def pooch_mute(silent: bool | None = True) -> None: Whether to silence or activate the :mod:`pooch` cache manager logger messages to the console. Defaults to ``True``. + Returns + ------- + bool + The previous value of :data:`GEOVISTA_POOCH_MUTE`. + Notes ----- .. versionadded:: 0.5.0 """ - global GEOVISTA_POOCH_MUTE + global GEOVISTA_POOCH_MUTE # noqa: PLW0603 level = "WARNING" if silent else "NOTSET" pooch.utils.get_logger().setLevel(level) + original = GEOVISTA_POOCH_MUTE GEOVISTA_POOCH_MUTE = silent + return original def reload_registry(fname: str | None = None) -> None: diff --git a/src/geovista/cli.py b/src/geovista/cli.py index 1536a632..a0bae6b8 100644 --- a/src/geovista/cli.py +++ b/src/geovista/cli.py @@ -24,7 +24,7 @@ import lazy_loader as lazy from ._version import version as __version__ -from .cache import CACHE, GEOVISTA_POOCH_MUTE, pooch_mute +from .cache import CACHE, pooch_mute from .common import get_modules from .config import resources from .geoplotter import GeoPlotter @@ -90,8 +90,7 @@ def _download_group( n_fnames: int = len(fnames) width: int = len(str(n_fnames)) - status = GEOVISTA_POOCH_MUTE - pooch_mute(silent=True) + previous = pooch_mute(silent=True) click.echo(f"Downloading {n_fnames} {name}registered asset{_plural(n_fnames)}:") for i, fname in enumerate(fnames): @@ -111,7 +110,7 @@ def _download_group( click.secho(f"{CACHE.abspath}", fg=fg_colour) click.echo("👍 All done!") - pooch_mute(status) + _ = pooch_mute(silent=previous) def _groups() -> list[str]: diff --git a/tests/cache/test_pooch_mute.py b/tests/cache/test_pooch_mute.py index fd112511..ab077c19 100644 --- a/tests/cache/test_pooch_mute.py +++ b/tests/cache/test_pooch_mute.py @@ -17,22 +17,25 @@ def test(): logger = get_logger() # default silent kwarg - pooch_mute() + previous = pooch_mute() assert logger.getEffectiveLevel() == 30 from geovista.cache import GEOVISTA_POOCH_MUTE assert GEOVISTA_POOCH_MUTE is True + assert previous is False # explicit verbose - pooch_mute(silent=False) + previous = pooch_mute(silent=False) assert logger.getEffectiveLevel() == 0 from geovista.cache import GEOVISTA_POOCH_MUTE assert GEOVISTA_POOCH_MUTE is False + assert previous is True # explicit silence - pooch_mute(silent=True) + previous = pooch_mute(silent=True) assert logger.getEffectiveLevel() == 30 from geovista.cache import GEOVISTA_POOCH_MUTE assert GEOVISTA_POOCH_MUTE is True + assert previous is False diff --git a/tests/core/test_slice_lines.py b/tests/core/test_slice_lines.py index add33840..4ce31c80 100644 --- a/tests/core/test_slice_lines.py +++ b/tests/core/test_slice_lines.py @@ -87,6 +87,7 @@ def antimeridian_count(mesh: pv.PolyData) -> int: return np.sum(mask) +# TODO @bjlittle: investigate this failing test - thread safety? side-effect? # @pytest.mark.parametrize( # "coastlines, kind", # [