Skip to content

Commit 1ef9fb4

Browse files
seismanweiji14
andauthored
Enable ruff's pylint rules (PL) and remove pylint (#2815)
* Enable ruff's pylint rules (PL) but ignore PLR2004 * Remove pylint settings from pyproject.toml * Remove all 'pylint: disable' directives * Use noqa to suppress some ruff errors * Fix a lint issue in timestamp.py * Fully remove pylint from Makefile, CI, docs, and environment.yml * Update doc/contributing.md Co-authored-by: Wei Ji <[email protected]>
1 parent 519fd03 commit 1ef9fb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+90
-168
lines changed

.github/workflows/style_checks.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,13 @@ jobs:
3434

3535
- name: Install packages
3636
run: |
37-
python -m pip install blackdoc docformatter pylint ruff
37+
python -m pip install blackdoc docformatter ruff
3838
python -m pip list
3939
sudo apt-get install dos2unix
4040
4141
- name: Formatting check (blackdoc, docformatter, ruff)
4242
run: make check
4343

44-
- name: Linting (pylint)
45-
run: make lint
46-
4744
- name: Ensure files use UNIX line breaks and have 644 permission
4845
run: |
4946
find . -type f -not -path '*/\.git/*' -exec grep -Iq . {} \; -exec dos2unix --quiet {} \;

Makefile

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ help:
1818
@echo " format run blackdoc, docformatter and ruff to automatically format the code"
1919
@echo " check run code style and quality checks (blackdoc, docformatter, ruff)"
2020
@echo " codespell run codespell to check common misspellings"
21-
@echo " lint run pylint for a deeper (and slower) quality check"
2221
@echo " clean clean up build and generated files"
2322
@echo " distclean clean up build and generated files, including project metadata files"
2423
@echo ""
@@ -74,9 +73,6 @@ check:
7473
codespell:
7574
@codespell
7675

77-
lint:
78-
pylint $(LINT_FILES)
79-
8076
clean:
8177
find . -name "*.pyc" -exec rm -v {} +
8278
find . -name "*~" -exec rm -v {} +

doc/conf.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
"""
22
Sphinx documentation configuration file.
33
"""
4-
# pylint: disable=invalid-name
5-
64
import datetime
75
from importlib.metadata import metadata
86

97
# ruff: isort: off
10-
from sphinx_gallery.sorting import ( # pylint: disable=no-name-in-module
11-
ExplicitOrder,
12-
ExampleTitleSortKey,
13-
)
8+
from sphinx_gallery.sorting import ExplicitOrder, ExampleTitleSortKey
149
import pygmt
1510
from pygmt import __commit__, __version__
1611
from pygmt.sphinx_gallery import PyGMTScraper
@@ -139,7 +134,7 @@
139134
# General information about the project
140135
year = datetime.date.today().year
141136
project = "PyGMT"
142-
copyright = f"2017-{year}, The PyGMT Developers" # pylint: disable=redefined-builtin
137+
copyright = f"2017-{year}, The PyGMT Developers"
143138
if len(__version__.split("+")) > 1 or __version__ == "unknown":
144139
version = "dev"
145140
# Set base_url for stable version

doc/contributing.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,14 @@ editors or IDEs. We consistently use `# %%` as code block separators (please
505505
refer to [issue #2660](https://github.com/GenericMappingTools/pygmt/issues/2660)
506506
for the discussions) and require at least one separator in all example files.
507507

508-
We also use [ruff](https://docs.astral.sh/ruff) and
509-
[pylint](https://pylint.pycqa.org/) to check the quality of the code and quickly catch
510-
common errors.
508+
We also use [ruff](https://docs.astral.sh/ruff) to check the quality of the code
509+
and quickly catch common errors.
510+
511511
The [`Makefile`](https://github.com/GenericMappingTools/pygmt/blob/main/Makefile)
512-
contains rules for running both checks:
512+
contains rules for running the linter checks:
513513

514514
```bash
515515
make check # Runs blackdoc, docformatter, ruff (in check mode)
516-
make lint # Runs pylint, which is a bit slower
517516
```
518517

519518
### Testing your Code

environment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies:
2525
- blackdoc
2626
- codespell
2727
- docformatter>=1.7.2
28-
- pylint
2928
- ruff
3029
# Dev dependencies (unit testing)
3130
- matplotlib

pygmt/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def print_clib_info(file=sys.stdout):
8383
Includes the GMT version, default values for parameters, the path to the
8484
``libgmt`` shared library, and GMT directories.
8585
"""
86-
from pygmt.clib import Session # pylint: disable=import-outside-toplevel
86+
from pygmt.clib import Session
8787

8888
lines = ["GMT library information:"]
8989
with Session() as ses:
@@ -104,7 +104,7 @@ def show_versions(file=sys.stdout):
104104
- Core dependency versions (NumPy, Pandas, Xarray, etc)
105105
- GMT library information
106106
"""
107-
# pylint: disable=import-outside-toplevel
107+
108108
import importlib
109109
import platform
110110
import subprocess

pygmt/clib/loading.py

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ def check_libgmt(libgmt):
163163
functions = ["Create_Session", "Get_Enum", "Call_Module", "Destroy_Session"]
164164
for func in functions:
165165
if not hasattr(libgmt, "GMT_" + func):
166-
# pylint: disable=protected-access
167166
msg = (
168167
f"Error loading '{libgmt._name}'. Couldn't access function GMT_{func}. "
169168
"Ensure that you have installed an up-to-date GMT version 6 library. "

pygmt/clib/session.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def info(self):
175175
Dictionary with the GMT version and default paths and parameters.
176176
"""
177177
if not hasattr(self, "_info"):
178-
self._info = { # pylint: disable=attribute-defined-outside-init
178+
self._info = {
179179
"version": self.get_default("API_VERSION"),
180180
"padding": self.get_default("API_PAD"),
181181
# API_BINDIR points to the directory of the Python interpreter
@@ -312,7 +312,6 @@ def get_libgmt_func(self, name, argtypes=None, restype=None):
312312
<class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>
313313
"""
314314
if not hasattr(self, "_libgmt"):
315-
# pylint: disable=attribute-defined-outside-init
316315
self._libgmt = load_libgmt()
317316
function = getattr(self._libgmt, name)
318317
if argtypes is not None:
@@ -349,7 +348,7 @@ def create(self, name):
349348
"""
350349
try:
351350
# Won't raise an exception if there is a currently open session
352-
self.session_pointer # pylint: disable=pointless-statement
351+
self.session_pointer
353352
# In this case, fail to create a new session until the old one is
354353
# destroyed
355354
raise GMTCLibError(
@@ -369,10 +368,10 @@ def create(self, name):
369368

370369
# Capture the output printed by GMT into this list. Will use it later
371370
# to generate error messages for the exceptions raised by API calls.
372-
self._error_log = [] # pylint: disable=attribute-defined-outside-init
371+
self._error_log = []
373372

374373
@ctp.CFUNCTYPE(ctp.c_int, ctp.c_void_p, ctp.c_char_p)
375-
def print_func(file_pointer, message): # pylint: disable=unused-argument
374+
def print_func(file_pointer, message):
376375
"""
377376
Callback function that the GMT C API will use to print log and
378377
error messages.
@@ -389,7 +388,6 @@ def print_func(file_pointer, message): # pylint: disable=unused-argument
389388

390389
# Need to store a copy of the function because ctypes doesn't and it
391390
# will be garbage collected otherwise
392-
# pylint: disable=attribute-defined-outside-init
393391
self._print_callback = print_func
394392

395393
padding = self["GMT_PAD_DEFAULT"]
@@ -1468,7 +1466,7 @@ def virtualfile_from_grid(self, grid):
14681466
yield vfile
14691467

14701468
@fmt_docstring
1471-
def virtualfile_from_data(
1469+
def virtualfile_from_data( # noqa: PLR0912
14721470
self,
14731471
check_kind=None,
14741472
data=None,

pygmt/datasets/tile_map.py

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret
107107
* y (y) float64 -7.081e-10 -7.858e+04 ... -1.996e+07 ...
108108
* x (x) float64 -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07
109109
"""
110-
# pylint: disable=too-many-locals
111110
if contextily is None:
112111
raise ImportError(
113112
"Package `contextily` is required to be installed to use this function. "

pygmt/figure.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
try:
1010
import IPython
1111
except ImportError:
12-
IPython = None # pylint: disable=invalid-name
13-
12+
IPython = None
1413

1514
from pygmt.clib import Session
1615
from pygmt.exceptions import GMTError, GMTInvalidInput
@@ -34,7 +33,7 @@
3433

3534
# Show figures in Jupyter notebooks if available
3635
if IPython:
37-
get_ipython = IPython.get_ipython() # pylint: disable=invalid-name
36+
get_ipython = IPython.get_ipython()
3837
if get_ipython and "IPKernelApp" in get_ipython.config: # Jupyter Notebook enabled
3938
SHOW_CONFIG["method"] = "notebook"
4039

@@ -82,9 +81,7 @@ class Figure:
8281

8382
def __init__(self):
8483
self._name = unique_name()
85-
self._preview_dir = TemporaryDirectory( # pylint: disable=consider-using-with
86-
prefix=f"{self._name}-preview-"
87-
)
84+
self._preview_dir = TemporaryDirectory(prefix=f"{self._name}-preview-")
8885
self._activate_figure()
8986

9087
def __del__(self):
@@ -251,7 +248,7 @@ def psconvert(self, **kwargs):
251248
module="psconvert", args=f"{prefix_arg} {build_arg_string(kwargs)}"
252249
)
253250

254-
def savefig(
251+
def savefig( # noqa: PLR0912
255252
self,
256253
fname,
257254
transparent=False,
@@ -320,7 +317,6 @@ def savefig(
320317
:meth:`pygmt.Figure.psconvert`. Valid parameters are ``gs_path``,
321318
``gs_option``, ``resize``, ``bb_style``, and ``verbose``.
322319
"""
323-
# pylint: disable=too-many-branches
324320
# All supported formats
325321
fmts = {
326322
"bmp": "b",
@@ -518,7 +514,7 @@ def _repr_html_(self):
518514
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
519515
return html.format(image=base64_png.decode("utf-8"), width=500)
520516

521-
from pygmt.src import ( # pylint: disable=import-outside-toplevel
517+
from pygmt.src import (
522518
basemap,
523519
coast,
524520
colorbar,

pygmt/helpers/tempfile.py

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def tempfile_from_geojson(geojson):
126126
E.g. '1a2b3c4d5e6.gmt'.
127127
"""
128128
with GMTTempFile(suffix=".gmt") as tmpfile:
129-
# pylint: disable=import-outside-toplevel
130129
import geopandas as gpd
131130

132131
os.remove(tmpfile.name) # ensure file is deleted first

pygmt/helpers/testing.py

-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,10 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag
7373
...
7474
>>> shutil.rmtree(path="tmp_result_images") # cleanup folder if tests pass
7575
"""
76-
# pylint: disable=invalid-name
7776
ALLOWED_CHARS = set(string.digits + string.ascii_letters + "_-[]()")
7877
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
7978

8079
def decorator(func):
81-
# pylint: disable=import-outside-toplevel
8280
import pytest
8381
from matplotlib.testing.compare import compare_images
8482

pygmt/helpers/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def launch_external_viewer(fname, waiting=0):
499499
elif os_name == "darwin": # Darwin is macOS
500500
subprocess.run(["open", fname], check=False, **run_args)
501501
elif os_name == "win32":
502-
os.startfile(fname) # pylint: disable=no-member
502+
os.startfile(fname)
503503
else:
504504
webbrowser.open_new_tab(f"file://{fname}")
505505
if waiting > 0:

pygmt/sphinx_gallery.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pygmt.figure import SHOWED_FIGURES
1010

1111

12-
class PyGMTScraper: # pylint: disable=too-few-public-methods
12+
class PyGMTScraper:
1313
"""
1414
Save ``pygmt.Figure`` objects that had their ``show`` method called.
1515

pygmt/src/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
Source code for PyGMT methods.
33
"""
4-
# pylint: disable=import-outside-toplevel
5-
64
from pygmt.src.basemap import basemap
75
from pygmt.src.binstats import binstats
86
from pygmt.src.blockm import blockmean, blockmedian, blockmode

pygmt/src/basemap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ def basemap(self, **kwargs):
8282
{perspective}
8383
{transparency}
8484
"""
85-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
85+
kwargs = self._preprocess(**kwargs)
8686
with Session() as lib:
8787
lib.call_module(module="basemap", args=build_arg_string(kwargs))

pygmt/src/coast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def coast(self, **kwargs):
201201
>>> # Show the plot
202202
>>> fig.show()
203203
"""
204-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
204+
kwargs = self._preprocess(**kwargs)
205205
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs):
206206
raise GMTInvalidInput(
207207
"""At least one of the following parameters must be specified:

pygmt/src/colorbar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ def colorbar(self, **kwargs):
144144
>>> # Show the plot
145145
>>> fig.show()
146146
"""
147-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
147+
kwargs = self._preprocess(**kwargs)
148148
with Session() as lib:
149149
lib.call_module(module="colorbar", args=build_arg_string(kwargs))

pygmt/src/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pygmt.clib import Session
77

88

9-
class config: # pylint: disable=invalid-name
9+
class config:
1010
"""
1111
Set GMT defaults globally or locally.
1212

pygmt/src/contour.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs):
112112
{perspective}
113113
{transparency}
114114
"""
115-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
115+
kwargs = self._preprocess(**kwargs)
116116

117117
with Session() as lib:
118118
file_context = lib.virtualfile_from_data(

pygmt/src/grdcontour.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def grdcontour(self, grid, **kwargs):
121121
>>> # show the plot
122122
>>> fig.show()
123123
"""
124-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
124+
kwargs = self._preprocess(**kwargs)
125125
with Session() as lib:
126126
file_context = lib.virtualfile_from_data(check_kind="raster", data=grid)
127127
with file_context as fname:

pygmt/src/grdhisteq.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
__doctest_skip__ = ["grdhisteq.*"]
2020

2121

22-
class grdhisteq: # pylint: disable=invalid-name
22+
class grdhisteq:
2323
r"""
2424
Perform histogram equalization for a grid.
2525

pygmt/src/grdimage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def grdimage(self, grid, **kwargs):
173173
>>> # show the plot
174174
>>> fig.show()
175175
"""
176-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
176+
kwargs = self._preprocess(**kwargs)
177177

178178
with Session() as lib:
179179
with lib.virtualfile_from_data(

pygmt/src/grdview.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def grdview(self, grid, **kwargs):
144144
>>> # show the plot
145145
>>> fig.show()
146146
"""
147-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
147+
kwargs = self._preprocess(**kwargs)
148148
with Session() as lib:
149149
with lib.virtualfile_from_data(
150150
check_kind="raster", data=grid

pygmt/src/histogram.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def histogram(self, data, **kwargs):
132132
{transparency}
133133
{wrap}
134134
"""
135-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
135+
kwargs = self._preprocess(**kwargs)
136136
with Session() as lib:
137137
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
138138
with file_context as infile:

pygmt/src/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ def image(self, imagefile, **kwargs):
6666
{perspective}
6767
{transparency}
6868
"""
69-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
69+
kwargs = self._preprocess(**kwargs)
7070
with Session() as lib:
7171
lib.call_module(module="image", args=build_arg_string(kwargs, infile=imagefile))

pygmt/src/inset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def inset(self, **kwargs):
132132
>>> fig.logo(position="jBR+o0.2c+w3c")
133133
>>> fig.show()
134134
"""
135-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
135+
kwargs = self._preprocess(**kwargs)
136136
with Session() as lib:
137137
try:
138138
lib.call_module(module="inset", args=f"begin {build_arg_string(kwargs)}")

pygmt/src/legend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
6767
{perspective}
6868
{transparency}
6969
"""
70-
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
70+
kwargs = self._preprocess(**kwargs)
7171

7272
if kwargs.get("D") is None:
7373
kwargs["D"] = position

0 commit comments

Comments
 (0)