Skip to content

Commit

Permalink
ruff: PLW compliance (#1215)
Browse files Browse the repository at this point in the history
* ruff: PLW compliance

* add changelog news fragment
  • Loading branch information
bjlittle authored Nov 20, 2024
1 parent a0b15cb commit 24ab6b5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
9 changes: 0 additions & 9 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
]
2 changes: 2 additions & 0 deletions changelog/1215.contributor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Complied with `ruff <https://github.com/astral-sh/ruff>`__
``pylint-warning`` (``PLW``) rules. (:user:`bjlittle`)
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 9 additions & 2 deletions src/geovista/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions src/geovista/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions tests/cache/test_pooch_mute.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ def test():
logger = get_logger()

# default silent kwarg
pooch_mute()
_ = pooch_mute()
assert logger.getEffectiveLevel() == 30
from geovista.cache import GEOVISTA_POOCH_MUTE

assert GEOVISTA_POOCH_MUTE is True

# explicit verbose
pooch_mute(silent=False)
_ = pooch_mute(silent=False)
assert logger.getEffectiveLevel() == 0
from geovista.cache import GEOVISTA_POOCH_MUTE

assert GEOVISTA_POOCH_MUTE is False

# explicit silence
pooch_mute(silent=True)
_ = pooch_mute(silent=True)
assert logger.getEffectiveLevel() == 30
from geovista.cache import GEOVISTA_POOCH_MUTE

Expand Down
1 change: 1 addition & 0 deletions tests/core/test_slice_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
# [
Expand Down

0 comments on commit 24ab6b5

Please sign in to comment.