From 4151f6090a0ca031360ae20263977df628dba635 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 28 Jul 2026 11:46:18 +0800 Subject: [PATCH] Ruff: Enable RUF106 (rule-codes-in-suppression-comments) --- doc/conf.py | 2 +- examples/gallery/images/cross_section.py | 2 +- examples/gallery/images/rgb_image.py | 2 +- examples/tutorials/advanced/non_ascii_text.py | 2 +- pygmt/alias.py | 2 +- pygmt/clib/session.py | 12 ++++++------ pygmt/datasets/load_remote_dataset.py | 2 +- pygmt/datasets/samples.py | 2 +- pygmt/datasets/tile_map.py | 2 +- pygmt/datatypes/dataset.py | 6 +++--- pygmt/datatypes/grid.py | 2 +- pygmt/datatypes/header.py | 2 +- pygmt/datatypes/image.py | 2 +- pygmt/exceptions.py | 6 +++--- pygmt/helpers/decorators.py | 2 +- pygmt/helpers/tempfile.py | 4 ++-- pygmt/helpers/testing.py | 8 +++++--- pygmt/helpers/utils.py | 10 +++++----- pygmt/params/base.py | 2 +- pygmt/sphinx_gallery.py | 2 +- pygmt/src/colorbar.py | 4 ++-- pygmt/src/config.py | 2 +- pygmt/src/grdfilter.py | 6 +++--- pygmt/src/grdgradient.py | 2 +- pygmt/src/grdhisteq.py | 2 +- pygmt/src/grdmask.py | 2 +- pygmt/src/grdview.py | 2 +- pygmt/src/plot.py | 2 +- pygmt/src/plot3d.py | 2 +- pygmt/src/pygmtlogo.py | 6 +++--- pygmt/src/subplot.py | 2 +- pygmt/src/text.py | 2 +- pygmt/src/triangulate.py | 2 +- pygmt/tests/test_clib.py | 6 +++--- pygmt/tests/test_clib_to_numpy.py | 2 +- pygmt/tests/test_clib_virtualfile_in.py | 2 +- pygmt/tests/test_datasets_samples.py | 2 +- pygmt/tests/test_figure.py | 8 +++++--- pygmt/tests/test_session_management.py | 2 +- pygmt/tests/test_text.py | 6 +++--- pygmt/xarray/backend.py | 2 +- pyproject.toml | 1 + 42 files changed, 73 insertions(+), 68 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 00f974fa5e1..d3484bbc652 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -26,7 +26,7 @@ # Projection information. project = "PyGMT" author = "The PyGMT Developers" -copyright = f"2017-{datetime.date.today().year}, {author}" # ruff: ignore[A001] +copyright = f"2017-{datetime.date.today().year}, {author}" # ruff: ignore[builtin-variable-shadowing] version = "dev" if isdev else __version__ release = __version__ diff --git a/examples/gallery/images/cross_section.py b/examples/gallery/images/cross_section.py index 52b83623d8a..3cf739e5a7d 100644 --- a/examples/gallery/images/cross_section.py +++ b/examples/gallery/images/cross_section.py @@ -20,7 +20,7 @@ region_map = [122, 149, 30, 49] # Chose a survey line with start point A and end point B -lonA, latA, lonB, latB = 126, 42, 146, 40 # ruff: ignore[N816] +lonA, latA, lonB, latB = 126, 42, 146, 40 # ruff: ignore[mixed-case-variable-in-global-scope] fig = pygmt.Figure() diff --git a/examples/gallery/images/rgb_image.py b/examples/gallery/images/rgb_image.py index 1bf22c8380c..1f02accd4f3 100644 --- a/examples/gallery/images/rgb_image.py +++ b/examples/gallery/images/rgb_image.py @@ -13,7 +13,7 @@ Data is sourced from a Cloud-Optimized GeoTIFF (COG) file hosted on `OpenAerialMap `_ under a `CC BY-NC 4.0 `_ license. -""" # ruff: ignore[RUF002] +""" # ruff: ignore[ambiguous-unicode-character-docstring] # %% import pygmt diff --git a/examples/tutorials/advanced/non_ascii_text.py b/examples/tutorials/advanced/non_ascii_text.py index 201f24b9f42..0fd886ad913 100644 --- a/examples/tutorials/advanced/non_ascii_text.py +++ b/examples/tutorials/advanced/non_ascii_text.py @@ -1,4 +1,4 @@ -# ruff: file-ignore[RUF001, RUF003] +# ruff: file-ignore[ambiguous-unicode-character-string, ambiguous-unicode-character-comment] """ Typesetting non-ASCII text -------------------------- diff --git a/pygmt/alias.py b/pygmt/alias.py index 6b0a415b41b..b73a23c6daa 100644 --- a/pygmt/alias.py +++ b/pygmt/alias.py @@ -331,7 +331,7 @@ def __init__(self, **kwargs): kwdict[option] = aliases._value super().__init__(kwdict) - def add_common(self, **kwargs): # ruff: ignore[PLR0912] + def add_common(self, **kwargs): # ruff: ignore[too-many-branches] """ Add common parameters to the alias dictionary. """ diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index b378a8245db..8c6cdc1252e 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -382,7 +382,7 @@ def create(self, name: str) -> None: self._error_log: list[str] = [] @ctp.CFUNCTYPE(ctp.c_int, ctp.c_void_p, ctp.c_char_p) - def print_func(file_pointer, message): # ruff: ignore[ARG001] + def print_func(file_pointer, message): # ruff: ignore[unused-function-argument] """ Callback function that the GMT C API will use to print log and error messages. @@ -399,7 +399,7 @@ def print_func(file_pointer, message): # ruff: ignore[ARG001] return 0 self._error_log.append(message) # Flush to make sure the messages are printed even if we have a crash. - print(message, file=sys.stderr, flush=True) # ruff: ignore[T201] + print(message, file=sys.stderr, flush=True) # ruff: ignore[print] return 0 # Need to store a copy of the function because ctypes doesn't and it will be @@ -1171,7 +1171,7 @@ def read_data( ------ GMTCLibError If the GMT API function fails to read the data. - """ # ruff: ignore[W505] + """ # ruff: ignore[doc-line-too-long] c_read_data = self.get_libgmt_func( "GMT_Read_Data", argtypes=[ @@ -1762,7 +1762,7 @@ def virtualfile_from_stringio( @deprecate_parameter( "required_data", "required", "v0.16.0", remove_version="v0.20.0" ) - def virtualfile_in( # ruff: ignore[PLR0912] + def virtualfile_in( # ruff: ignore[too-many-branches] self, check_kind=None, data=None, @@ -1920,7 +1920,7 @@ def virtualfile_in( # ruff: ignore[PLR0912] if hasattr(data, "items") and not hasattr(data, "to_frame"): # Dictionary, pandas.DataFrame or xarray.Dataset types. # pandas.Series will be handled below like a 1-D numpy.ndarray. - _data = [array for _, array in data.items()] # ruff: ignore[PERF102] + _data = [array for _, array in data.items()] # ruff: ignore[incorrect-dict-iterator] else: # Python list, tuple, numpy.ndarray, and pandas.Series types _data = np.atleast_2d(np.asanyarray(data).T) @@ -2354,7 +2354,7 @@ def extract_region(self) -> np.ndarray: ... region = lib.extract_region() >>> print(", ".join([f"{x:.2f}" for x in region])) -165.00, -150.00, 15.00, 25.00 - """ # ruff: ignore[RUF002] + """ # ruff: ignore[ambiguous-unicode-character-docstring] c_extract_region = self.get_libgmt_func( "GMT_Extract_Region", argtypes=[ctp.c_void_p, ctp.c_char_p, ctp.POINTER(ctp.c_double)], diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 2f84f8ea687..9ec1dd76269 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -11,7 +11,7 @@ with contextlib.suppress(ImportError): # rioxarray is needed to register the rio accessor - import rioxarray # ruff: ignore[F401] + import rioxarray # ruff: ignore[unused-import] class Resolution(NamedTuple): diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 8476587ac7b..1623967a9b9 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -339,7 +339,7 @@ def load_sample_data( 'usgs_quakes': 'Table of earthquakes from the USGS'} >>> # Load the sample bathymetry dataset >>> data = load_sample_data("bathymetry") - """ # ruff: ignore[W505] + """ # ruff: ignore[doc-line-too-long] if name not in datasets: raise GMTValueError(name, choices=datasets.keys(), description="dataset name") return datasets[name].func() diff --git a/pygmt/datasets/tile_map.py b/pygmt/datasets/tile_map.py index c856a1a33c6..697327a0870 100644 --- a/pygmt/datasets/tile_map.py +++ b/pygmt/datasets/tile_map.py @@ -18,7 +18,7 @@ _HAS_CONTEXTILY = False try: - import rioxarray # ruff: ignore[F401] + import rioxarray # ruff: ignore[unused-import] _HAS_RIOXARRAY = True except ImportError: diff --git a/pygmt/datatypes/dataset.py b/pygmt/datatypes/dataset.py index 608b47bffe6..a2ab793d5b9 100644 --- a/pygmt/datatypes/dataset.py +++ b/pygmt/datatypes/dataset.py @@ -11,7 +11,7 @@ import pandas as pd -class _GMT_DATASEGMENT(ctp.Structure): # ruff: ignore[N801] +class _GMT_DATASEGMENT(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT datasegment structure for holding a segment with multiple columns. """ @@ -38,7 +38,7 @@ class _GMT_DATASEGMENT(ctp.Structure): # ruff: ignore[N801] ] -class _GMT_DATATABLE(ctp.Structure): # ruff: ignore[N801] +class _GMT_DATATABLE(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT datatable structure for holding a table with multiple segments. """ @@ -65,7 +65,7 @@ class _GMT_DATATABLE(ctp.Structure): # ruff: ignore[N801] ] -class _GMT_DATASET(ctp.Structure): # ruff: ignore[N801] +class _GMT_DATASET(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT dataset structure for holding multiple tables (files). diff --git a/pygmt/datatypes/grid.py b/pygmt/datatypes/grid.py index 51e26518fce..e3cb8389e73 100644 --- a/pygmt/datatypes/grid.py +++ b/pygmt/datatypes/grid.py @@ -10,7 +10,7 @@ from pygmt.datatypes.header import _GMT_GRID_HEADER, gmt_grdfloat -class _GMT_GRID(ctp.Structure): # ruff: ignore[N801] +class _GMT_GRID(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT grid structure for holding a grid and its header. diff --git a/pygmt/datatypes/header.py b/pygmt/datatypes/header.py index 1b948d49bfe..afd60c08c28 100644 --- a/pygmt/datatypes/header.py +++ b/pygmt/datatypes/header.py @@ -66,7 +66,7 @@ def _parse_nameunits(nameunits: str) -> tuple[str, str | None]: return long_name, units -class _GMT_GRID_HEADER(ctp.Structure): # ruff: ignore[N801] +class _GMT_GRID_HEADER(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT grid header structure for metadata about the grid. diff --git a/pygmt/datatypes/image.py b/pygmt/datatypes/image.py index 6b4cb8de1ba..16d7b8e435d 100644 --- a/pygmt/datatypes/image.py +++ b/pygmt/datatypes/image.py @@ -16,7 +16,7 @@ ) -class _GMT_IMAGE(ctp.Structure): # ruff: ignore[N801] +class _GMT_IMAGE(ctp.Structure): # ruff: ignore[invalid-class-name] """ GMT image data structure. diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index cc0be1bf517..8aefc60d745 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -38,7 +38,7 @@ class GMTCLibNoSessionError(GMTCLibError): """ -class GMTInvalidInput(GMTError): # ruff: ignore[N818] +class GMTInvalidInput(GMTError): # ruff: ignore[error-suffix-on-exception-name] """ Raised when the input of a function/method is invalid. """ @@ -50,7 +50,7 @@ class GMTVersionError(GMTError): """ -class GMTImageComparisonFailure(AssertionError): # ruff: ignore[N818] +class GMTImageComparisonFailure(AssertionError): # ruff: ignore[error-suffix-on-exception-name] """ Raised when a comparison between two images fails. """ @@ -99,7 +99,7 @@ class GMTValueError(GMTError, ValueError): Traceback (most recent call last): ... pygmt.exceptions.GMTValueError: Invalid value: 'invalid'. Explain why it's invalid. - """ # ruff: ignore[W505] + """ # ruff: ignore[doc-line-too-long] def __init__( self, diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 87465082b22..c33df145c73 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -454,7 +454,7 @@ def fmt_docstring(module_func): - J = projection - R = region - """ # ruff: ignore[D410, D411] + """ # ruff: ignore[no-blank-line-after-section, no-blank-line-before-section] filler_text = {} if hasattr(module_func, "aliases"): diff --git a/pygmt/helpers/tempfile.py b/pygmt/helpers/tempfile.py index 1ccec9be016..2b80e3b83a4 100644 --- a/pygmt/helpers/tempfile.py +++ b/pygmt/helpers/tempfile.py @@ -132,7 +132,7 @@ def tempfile_from_geojson(geojson): E.g. '1a2b3c4d5e6.gmt'. """ with GMTTempFile(suffix=".gmt") as tmpfile: - import geopandas # ruff: ignore[PLC0415] + import geopandas # ruff: ignore[import-outside-top-level] Path(tmpfile.name).unlink() # Ensure file is deleted first ogrgmt_kwargs = { @@ -162,7 +162,7 @@ def tempfile_from_geojson(geojson): geojson.to_file(**ogrgmt_kwargs) except AttributeError: # Other 'geo' formats which implement __geo_interface__ - import json # ruff: ignore[PLC0415] + import json # ruff: ignore[import-outside-top-level] jsontext = json.dumps(geojson.__geo_interface__) geopandas.read_file(filename=io.StringIO(jsontext)).to_file(**ogrgmt_kwargs) diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index bd7dfbaf873..fb12d790ce5 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -75,8 +75,10 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag keyword_only = inspect.Parameter.KEYWORD_ONLY def decorator(func): - import pytest # ruff: ignore[PLC0415] - from matplotlib.testing.compare import compare_images # ruff: ignore[PLC0415] + # ruff: disable[import-outside-top-level] + import pytest + from matplotlib.testing.compare import compare_images + # ruff: enable[import-outside-top-level] Path(result_dir).mkdir(parents=True, exist_ok=True) old_sig = inspect.signature(func) @@ -191,7 +193,7 @@ def skip_if_no(package): A pytest.mark.skipif to use as either a test decorator or a parametrization mark. """ - import pytest # ruff: ignore[PLC0415] + import pytest # ruff: ignore[import-outside-top-level] try: _ = importlib.import_module(name=package) diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 91e520f04e9..b16885689ff 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -43,7 +43,7 @@ ] -def _validate_data_input( # ruff: ignore[PLR0912] +def _validate_data_input( # ruff: ignore[too-many-branches] data=None, x=None, y=None, z=None, required=True, mincols=2, kind=None ) -> None: """ @@ -217,7 +217,7 @@ def _contains_apostrophe_or_backtick(argstr: str) -> bool: True >>> _contains_apostrophe_or_backtick("12AB'`") True - """ # ruff: ignore[RUF002] + """ # ruff: ignore[ambiguous-unicode-character-docstring] return "'" in argstr or "`" in argstr @@ -452,7 +452,7 @@ def non_ascii_to_octal(argstr: str, encoding: Encoding = "ISOLatin1+") -> str: '12AB\\340\\341\\342\\343\\344\\345@~\\142@~@%34%\\254@%%@%34%\\255@%%' >>> non_ascii_to_octal("'‘’\"“”") '\\234\\140\\047"\\216\\217' - """ # ruff: ignore[RUF002] + """ # ruff: ignore[ambiguous-unicode-character-docstring] # Return the input string if it only contains printable ASCII characters, excluding # apostrophe (') and backtick (`). if encoding == "ascii" or ( @@ -481,7 +481,7 @@ def non_ascii_to_octal(argstr: str, encoding: Encoding = "ISOLatin1+") -> str: return argstr.translate(str.maketrans(mapping)) -def build_arg_list( # ruff: ignore[PLR0912] +def build_arg_list( # ruff: ignore[too-many-branches] kwdict: Mapping[str, Any], confdict: Mapping[str, Any] | None = None, infile: PathLike | Sequence[PathLike] | None = None, @@ -712,7 +712,7 @@ def launch_external_viewer(fname: PathLike, waiting: float = 0) -> None: case "darwin": # macOS subprocess.run([shutil.which("open"), fname], check=False, **run_args) # type:ignore[call-overload] case "win32": # Windows - os.startfile(fname) # type:ignore[attr-defined] # ruff: ignore[S606] + os.startfile(fname) # type:ignore[attr-defined] # ruff: ignore[start-process-with-no-shell] case _: # Fall back to the browser if can't recognize the operating system. webbrowser.open_new_tab(f"file://{Path(fname).resolve()}") if waiting > 0: diff --git a/pygmt/params/base.py b/pygmt/params/base.py index c8ec9b2beed..f7460ebc09a 100644 --- a/pygmt/params/base.py +++ b/pygmt/params/base.py @@ -62,7 +62,7 @@ def __post_init__(self): """ self._validate() - def _validate(self): # ruff: ignore[B027] + def _validate(self): # ruff: ignore[empty-method-without-abstract-decorator] """ Validate the parameters of the object. diff --git a/pygmt/sphinx_gallery.py b/pygmt/sphinx_gallery.py index e9ac65bd060..b397789742b 100644 --- a/pygmt/sphinx_gallery.py +++ b/pygmt/sphinx_gallery.py @@ -19,7 +19,7 @@ class PyGMTScraper: ``conf.py`` as the ``"image_scrapers"`` argument. """ - def __call__(self, block, block_vars, gallery_conf): # ruff: ignore[ARG002] + def __call__(self, block, block_vars, gallery_conf): # ruff: ignore[unused-method-argument] """ Called by sphinx-gallery to save the figures generated after running code. """ diff --git a/pygmt/src/colorbar.py b/pygmt/src/colorbar.py index 660f3464e90..9d264e42787 100644 --- a/pygmt/src/colorbar.py +++ b/pygmt/src/colorbar.py @@ -92,7 +92,7 @@ def _build_frame( return Frame(xaxis=xaxis, yaxis=yaxis) -def _alias_option_D( # ruff: ignore[N802] +def _alias_option_D( # ruff: ignore[invalid-function-name] position=None, length=None, width=None, @@ -220,7 +220,7 @@ def _alias_option_D( # ruff: ignore[N802] ] -def _alias_option_N(dpi=None): # ruff: ignore[N802] +def _alias_option_N(dpi=None): # ruff: ignore[invalid-function-name] """ Return an Alias object for the colorbar encoding setting. diff --git a/pygmt/src/config.py b/pygmt/src/config.py index c521e672e7d..d40ef5dac98 100644 --- a/pygmt/src/config.py +++ b/pygmt/src/config.py @@ -9,7 +9,7 @@ from pygmt.clib import Session -class config: # ruff: ignore[N801] +class config: # ruff: ignore[invalid-class-name] """ Change GMT default settings globally or locally. diff --git a/pygmt/src/grdfilter.py b/pygmt/src/grdfilter.py index 1d593c97ea8..95034815c9b 100644 --- a/pygmt/src/grdfilter.py +++ b/pygmt/src/grdfilter.py @@ -15,8 +15,8 @@ __doctest_skip__ = ["grdfilter"] -def _alias_option_F( # ruff: ignore[N802] - filter=None, # ruff: ignore[A002] +def _alias_option_F( # ruff: ignore[invalid-function-name] + filter=None, # ruff: ignore[builtin-argument-shadowing] width=None, highpass=False, ): @@ -70,7 +70,7 @@ def _alias_option_F( # ruff: ignore[N802] def grdfilter( grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, - filter: Literal[ # ruff: ignore[A002] + filter: Literal[ # ruff: ignore[builtin-argument-shadowing] "boxcar", "cosarch", "gaussian", "minall", "minpos", "maxall", "maxneg" ] | str diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index 6a638ffcf8d..f73fcf47d3e 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -15,7 +15,7 @@ __doctest_skip__ = ["grdgradient"] -def _alias_option_N( # ruff: ignore[N802] +def _alias_option_N( # ruff: ignore[invalid-function-name] normalize=False, norm_amp=None, norm_ambient=None, diff --git a/pygmt/src/grdhisteq.py b/pygmt/src/grdhisteq.py index 906bfcd15f7..b471e5808b0 100644 --- a/pygmt/src/grdhisteq.py +++ b/pygmt/src/grdhisteq.py @@ -22,7 +22,7 @@ __doctest_skip__ = ["grdhisteq.*"] -class grdhisteq: # ruff: ignore[N801] +class grdhisteq: # ruff: ignore[invalid-class-name] r""" Perform histogram equalization for a grid. diff --git a/pygmt/src/grdmask.py b/pygmt/src/grdmask.py index 5b163af9f0a..58a5f491efa 100644 --- a/pygmt/src/grdmask.py +++ b/pygmt/src/grdmask.py @@ -15,7 +15,7 @@ __doctest_skip__ = ["grdmask"] -def _alias_option_N( # ruff: ignore[N802] +def _alias_option_N( # ruff: ignore[invalid-function-name] outside: float | None = None, edge: float | Literal["z", "id"] | None = None, inside: float | Literal["z", "id"] | None = None, diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index cf195ceb039..19f8748dc7e 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -24,7 +24,7 @@ __doctest_skip__ = ["grdview"] -def _alias_option_Q( # ruff: ignore[N802] +def _alias_option_Q( # ruff: ignore[invalid-function-name] surftype=None, dpi=None, mesh_fill=None, monochrome=False, nan_transparent=False ): """ diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 3c787a414b8..bb2d5097e76 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -42,7 +42,7 @@ l="label", w="wrap", ) -def plot( # ruff: ignore[PLR0912] +def plot( # ruff: ignore[too-many-branches] self, data: PathLike | TableLike | None = None, x=None, diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index 9ad6900b659..00aae4b1e18 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -41,7 +41,7 @@ l="label", w="wrap", ) -def plot3d( # ruff: ignore[PLR0912] +def plot3d( # ruff: ignore[too-many-branches] self, data: PathLike | TableLike | None = None, x=None, diff --git a/pygmt/src/pygmtlogo.py b/pygmt/src/pygmtlogo.py index 69126fd80d5..ea4338999d5 100644 --- a/pygmt/src/pygmtlogo.py +++ b/pygmt/src/pygmtlogo.py @@ -17,7 +17,7 @@ __doctest_skip__ = ["pygmtlogo"] -def _create_logo( # ruff: ignore[PLR0915] +def _create_logo( # ruff: ignore[too-many-statements] shape: Literal["circle", "hexagon"] = "circle", theme: Literal["light", "dark"] = "light", wordmark: Literal["none", "horizontal", "vertical"] = "none", @@ -28,7 +28,7 @@ def _create_logo( # ruff: ignore[PLR0915] """ Create the PyGMT logo using PyGMT. """ - from pygmt.figure import Figure # ruff: ignore[PLC0415] + from pygmt.figure import Figure # ruff: ignore[import-outside-top-level] # Helpful definitions size = 4 @@ -242,7 +242,7 @@ def _compass_lines(): # Helpful for implementing the logo; not included in the logo if debug: - from pygmt import config # ruff: ignore[PLC0415] + from pygmt import config # ruff: ignore[import-outside-top-level] # Gridlines with config(MAP_GRID_PEN="0.1p,gray30"): diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 6fab75c14b7..4f511c93fe6 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -22,7 +22,7 @@ from pygmt.src._common import _parse_position -def _alias_option_A( # ruff: ignore[N802] +def _alias_option_A( # ruff: ignore[invalid-function-name] tag: str | bool = False, tag_position: AnchorCode | Position | None = None, tag_box: Box | None = None, diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 645ca598545..c8b6e17d0b9 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -32,7 +32,7 @@ it="use_word", w="wrap", ) -def text( # ruff: ignore[PLR0912, PLR0915] +def text( # ruff: ignore[too-many-branches, too-many-statements] self, textfiles: PathLike | TableLike | None = None, x=None, diff --git a/pygmt/src/triangulate.py b/pygmt/src/triangulate.py index f9b7b43c206..bf75d64ada5 100644 --- a/pygmt/src/triangulate.py +++ b/pygmt/src/triangulate.py @@ -20,7 +20,7 @@ ) -class triangulate: # ruff: ignore[N801] +class triangulate: # ruff: ignore[invalid-class-name] """ Delaunay triangulation or Voronoi partitioning and gridding of Cartesian data. diff --git a/pygmt/tests/test_clib.py b/pygmt/tests/test_clib.py index 31ec54511f1..bdfb3989e7b 100644 --- a/pygmt/tests/test_clib.py +++ b/pygmt/tests/test_clib.py @@ -32,7 +32,7 @@ def mock(session, func, returns=None, mock_func=None): """ if mock_func is None: - def mock_api_function(*args): # ruff: ignore[ARG001] + def mock_api_function(*args): # ruff: ignore[unused-function-argument] """ A mock GMT API function that always returns a given value. """ @@ -215,7 +215,7 @@ def test_info_dict(): assert lib.info # Mock GMT_Get_Default to return always the same string - def mock_defaults(api, name, value): # ruff: ignore[ARG001] + def mock_defaults(api, name, value): # ruff: ignore[unused-function-argument] """ Put 'bla' in the value buffer. """ @@ -247,7 +247,7 @@ def test_fails_for_wrong_version(monkeypatch): assert clib.__gmt_version__.split(".")[0] == "6" # Monkeypatch the version string returned by pygmt.clib.loading.get_gmt_version. - mpatch.setattr(clib.loading, "get_gmt_version", lambda libgmt: "5.4.3") # ruff: ignore[ARG005] + mpatch.setattr(clib.loading, "get_gmt_version", lambda libgmt: "5.4.3") # ruff: ignore[unused-lambda-argument] # Reload clib.session and check the __gmt_version__ string. importlib.reload(clib.session) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index 30ada24262e..a50a45356c0 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -18,7 +18,7 @@ _HAS_PYARROW = True except ImportError: - class pa: # ruff: ignore[N801] + class pa: # ruff: ignore[invalid-class-name] """ A dummy class to mimic pyarrow. """ diff --git a/pygmt/tests/test_clib_virtualfile_in.py b/pygmt/tests/test_clib_virtualfile_in.py index 82b2f424f53..d95122ef69e 100644 --- a/pygmt/tests/test_clib_virtualfile_in.py +++ b/pygmt/tests/test_clib_virtualfile_in.py @@ -74,7 +74,7 @@ def test_virtualfile_in_required_z_deprecated(): """ data = np.ones((5, 2)) with clib.Session() as lib: - with pytest.raises(GMTInvalidInput): # ruff: ignore[PT012] + with pytest.raises(GMTInvalidInput): # ruff: ignore[pytest-raises-with-multiple-statements] with pytest.warns(FutureWarning): with lib.virtualfile_in( data=data, required_z=True, check_kind="vector" diff --git a/pygmt/tests/test_datasets_samples.py b/pygmt/tests/test_datasets_samples.py index e97e009f85b..cc5761d45bf 100644 --- a/pygmt/tests/test_datasets_samples.py +++ b/pygmt/tests/test_datasets_samples.py @@ -191,7 +191,7 @@ def test_earth_relief_holes(): npt.assert_allclose(grid.max(), 1601) npt.assert_allclose(grid.min(), -4929.5) # Test for the NaN values in the remote file - assert grid[2, 21].isnull() # ruff: ignore[PD003] # Ruff's bug + assert grid[2, 21].isnull() # ruff: ignore[pandas-use-of-dot-is-null] # Ruff's bug def test_maunaloa_co2(): diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 64655ad2ce7..b9b6ec4cdcd 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -129,9 +129,11 @@ def test_figure_savefig_geotiff(): # Check if a TIFF is georeferenced or not if _HAS_RIOXARRAY: - import rioxarray # ruff: ignore[PLC0415] - from rasterio.errors import NotGeoreferencedWarning # ruff: ignore[PLC0415] - from rasterio.transform import Affine # ruff: ignore[PLC0415] + # ruff: disable[import-outside-top-level] + import rioxarray + from rasterio.errors import NotGeoreferencedWarning + from rasterio.transform import Affine + # ruff: enable[import-outside-top-level] # GeoTIFF with rioxarray.open_rasterio(geofname) as xds: diff --git a/pygmt/tests/test_session_management.py b/pygmt/tests/test_session_management.py index d24a73e4ba3..b3b842d457b 100644 --- a/pygmt/tests/test_session_management.py +++ b/pygmt/tests/test_session_management.py @@ -69,7 +69,7 @@ def _gmt_func_wrapper(figname): Currently, we have to import pygmt and reload it in each process. Workaround from https://github.com/GenericMappingTools/pygmt/issues/217#issuecomment-754774875. """ - import pygmt # ruff: ignore[PLC0415] + import pygmt # ruff: ignore[import-outside-top-level] reload(pygmt) fig = pygmt.Figure() diff --git a/pygmt/tests/test_text.py b/pygmt/tests/test_text.py index 4d1be324ec5..fa9d644734c 100644 --- a/pygmt/tests/test_text.py +++ b/pygmt/tests/test_text.py @@ -470,8 +470,8 @@ def test_text_nonascii(encoding): if encoding == "Standard+": # Temporarily set the PS_CHAR_ENCODING to "Standard+". config(PS_CHAR_ENCODING="Standard+") fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True) - fig.text(position="TL", text="position-text:°α") # ruff: ignore[RUF001] - fig.text(x=1, y=1, text="xytext:°α") # ruff: ignore[RUF001] + fig.text(position="TL", text="position-text:°α") # ruff: ignore[ambiguous-unicode-character-string] + fig.text(x=1, y=1, text="xytext:°α") # ruff: ignore[ambiguous-unicode-character-string] fig.text(x=[5, 5], y=[3, 5], text=["xytext1:αζ∆❡", "xytext2:∑π∇✉"]) return fig @@ -484,7 +484,7 @@ def test_text_quotation_marks(): See https://github.com/GenericMappingTools/pygmt/issues/3104 and https://github.com/GenericMappingTools/pygmt/issues/3476. """ - quotations = "` ' ‘ ’ \" “ ”" # ruff: ignore[RUF001] + quotations = "` ' ‘ ’ \" “ ”" # ruff: ignore[ambiguous-unicode-character-string] fig = Figure() fig.basemap( projection="X4c/2c", diff --git a/pygmt/xarray/backend.py b/pygmt/xarray/backend.py index b6c82985d2c..cc5a0f6322c 100644 --- a/pygmt/xarray/backend.py +++ b/pygmt/xarray/backend.py @@ -114,7 +114,7 @@ def open_dataset( # type: ignore[override] self, filename_or_obj: PathLike, *, - drop_variables=None, # ruff: ignore[ARG002] + drop_variables=None, # ruff: ignore[unused-method-argument] raster_kind: Literal["grid", "image"], region: Sequence[float] | str | None = None, # other backend specific keyword arguments diff --git a/pyproject.toml b/pyproject.toml index e040cd79f8e..fecd5c3e07d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -154,6 +154,7 @@ extend-select = [ "PLW1514", # {function_name} in text mode without explicit encoding argument "RUF027", # Possible f-string without an f prefix "RUF105", # Use `# ruff: ignore` rather than `# noqa` + "RUF106", # Rule code used instead of name in suppression comment ] ignore = [ "COM812", # Do not always add the trailing commas