Skip to content

Commit fbc4e97

Browse files
authored
Use ruff to format code snippets in docstrings and remove blackdoc (#2909)
1 parent 94e4598 commit fbc4e97

21 files changed

+25
-85
lines changed

.github/workflows/format-command.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# Install formatting tools
3333
- name: Install formatting tools
3434
run: |
35-
python -m pip install blackdoc docformatter ruff
35+
python -m pip install docformatter ruff
3636
python -m pip list
3737
sudo apt-get install dos2unix
3838

.github/workflows/style_checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ jobs:
3434

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

4444
- name: Ensure files use UNIX line breaks and have 644 permission

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ help:
1515
@echo " fulltest run the test suite (including all doctests)"
1616
@echo " doctest run the doctests only"
1717
@echo " test_no_images run the test suite (including all doctests) but skip image comparisons"
18-
@echo " format run blackdoc, docformatter and ruff to automatically format the code"
19-
@echo " check run code style and quality checks (blackdoc, docformatter, ruff)"
18+
@echo " format run docformatter and ruff to automatically format the code"
19+
@echo " check run code style and quality checks (docformatter and ruff)"
2020
@echo " codespell run codespell to check common misspellings"
2121
@echo " typecheck run mypy for static type check"
2222
@echo " clean clean up build and generated files"
@@ -61,13 +61,11 @@ test_no_images: _runtest
6161

6262
format:
6363
docformatter --in-place $(FORMAT_FILES)
64-
blackdoc $(FORMAT_FILES)
6564
ruff check --fix $(FORMAT_FILES)
6665
ruff format $(FORMAT_FILES)
6766

6867
check:
6968
docformatter --check $(FORMAT_FILES)
70-
blackdoc --check $(FORMAT_FILES)
7169
ruff check $(FORMAT_FILES)
7270
ruff format --check $(FORMAT_FILES)
7371

doc/contributing.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ code, be sure to follow the general guidelines in the
473473

474474
We use some tools to format the code so we don't have to think about it:
475475

476-
- [blackdoc](https://github.com/keewis/blackdoc)
477476
- [docformatter](https://github.com/myint/docformatter)
478477
- [ruff](https://docs.astral.sh/ruff)
479478

@@ -512,7 +511,7 @@ The [`Makefile`](https://github.com/GenericMappingTools/pygmt/blob/main/Makefile
512511
contains rules for running the linter checks:
513512

514513
```bash
515-
make check # Runs blackdoc, docformatter, ruff (in check mode)
514+
make check # Runs docformatter and ruff (in check mode)
516515
```
517516

518517
### Testing your Code

environment.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ dependencies:
2323
- make
2424
- pip
2525
# Dev dependencies (style checks)
26-
- blackdoc
2726
- codespell
2827
- docformatter>=1.7.2
29-
- ruff
28+
- ruff>=0.1.9
3029
# Dev dependencies (unit testing)
3130
- matplotlib
3231
- pytest-cov

pygmt/accessors.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ class GMTDataArrayAccessor:
5757
>>> lon = np.arange(0, 360 + interval, interval)
5858
>>> longrid, latgrid = np.meshgrid(lon, lat)
5959
>>> data = np.sin(np.deg2rad(longrid)) * np.cos(np.deg2rad(latgrid))
60-
>>> grid = xr.DataArray(
61-
... data, coords=[("latitude", lat), ("longitude", lon)]
62-
... )
60+
>>> grid = xr.DataArray(data, coords=[("latitude", lat), ("longitude", lon)])
6361
>>> # default to a gridline-registrated Cartesian grid
6462
>>> grid.gmt.registration, grid.gmt.gtype
6563
(0, 0)

pygmt/clib/session.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class Session:
140140
... ses.call_module("grdinfo", f"{fin} -C ->{fout.name}")
141141
... # Read the contents of the temp file before it's deleted.
142142
... print(fout.read().strip())
143-
...
144143
-55 -47 -24 -10 190 981 1 1 8 14 1 1
145144
"""
146145

@@ -305,7 +304,6 @@ def get_libgmt_func(self, name, argtypes=None, restype=None):
305304
... func = lib.get_libgmt_func(
306305
... "GMT_Destroy_Session", argtypes=[c_void_p], restype=c_int
307306
... )
308-
...
309307
>>> type(func)
310308
<class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>
311309
"""
@@ -546,13 +544,11 @@ def get_common(self, option):
546544
... lib.call_module("plot", "-T -Xw+1i -Yh-1i")
547545
... xshift = lib.get_common("X") # xshift/yshift are in inches
548546
... yshift = lib.get_common("Y")
549-
...
550547
>>> print(region, projection, timestamp, verbose, xshift, yshift)
551548
[ 0. 10. 10. 15.] True False 3 6.0 1.5
552549
>>> with Session() as lib:
553550
... lib.call_module("basemap", "-R0/10/10/15 -JX5i/2.5i -Baf")
554551
... lib.get_common("A")
555-
...
556552
Traceback (most recent call last):
557553
...
558554
pygmt.exceptions.GMTInvalidInput: Unknown GMT common option flag 'A'.
@@ -816,13 +812,11 @@ def _check_dtype_and_dim(self, array, ndim):
816812
>>> with Session() as ses:
817813
... gmttype = ses._check_dtype_and_dim(data, ndim=1)
818814
... gmttype == ses["GMT_DOUBLE"]
819-
...
820815
True
821816
>>> data = np.ones((5, 2), dtype="float32")
822817
>>> with Session() as ses:
823818
... gmttype = ses._check_dtype_and_dim(data, ndim=2)
824819
... gmttype == ses["GMT_FLOAT"]
825-
...
826820
True
827821
"""
828822
# Check that the array has the given number of dimensions
@@ -1150,7 +1144,6 @@ def open_virtual_file(self, family, geometry, direction, data):
11501144
... args = f"{vfile} ->{ofile.name}"
11511145
... lib.call_module("info", args)
11521146
... print(ofile.read().strip())
1153-
...
11541147
<vector memory>: N = 5 <0/4> <5/9>
11551148
"""
11561149
c_open_virtualfile = self.get_libgmt_func(
@@ -1241,7 +1234,6 @@ def virtualfile_from_vectors(self, *vectors):
12411234
... with GMTTempFile() as fout:
12421235
... ses.call_module("info", f"{fin} ->{fout.name}")
12431236
... print(fout.read().strip())
1244-
...
12451237
<vector memory>: N = 3 <1/3> <4/6> <7/9>
12461238
"""
12471239
# Conversion to a C-contiguous array needs to be done here and not in
@@ -1350,7 +1342,6 @@ def virtualfile_from_matrix(self, matrix):
13501342
... with GMTTempFile() as fout:
13511343
... ses.call_module("info", f"{fin} ->{fout.name}")
13521344
... print(fout.read().strip())
1353-
...
13541345
<matrix memory>: N = 4 <0/9> <1/10> <2/11>
13551346
"""
13561347
# Conversion to a C-contiguous array needs to be done here and not in
@@ -1432,7 +1423,6 @@ def virtualfile_from_grid(self, grid):
14321423
... args = f"{fin} -L0 -Cn ->{fout.name}"
14331424
... ses.call_module("grdinfo", args)
14341425
... print(fout.read().strip())
1435-
...
14361426
-55 -47 -24 -10 190 981 1 1 8 14 1 1
14371427
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype
14381428
"""
@@ -1520,14 +1510,11 @@ def virtualfile_from_data( # noqa: PLR0912
15201510
... ),
15211511
... )
15221512
>>> with Session() as ses:
1523-
... with ses.virtualfile_from_data(
1524-
... check_kind="vector", data=data
1525-
... ) as fin:
1513+
... with ses.virtualfile_from_data(check_kind="vector", data=data) as fin:
15261514
... # Send the output to a file so that we can read it
15271515
... with GMTTempFile() as fout:
15281516
... ses.call_module("info", fin + " ->" + fout.name)
15291517
... print(fout.read().strip())
1530-
...
15311518
<vector memory>: N = 3 <7/9> <4/6> <1/3>
15321519
"""
15331520
kind = data_kind(
@@ -1623,20 +1610,16 @@ def extract_region(self):
16231610
... )
16241611
>>> with Session() as lib:
16251612
... wesn = lib.extract_region()
1626-
...
16271613
>>> print(", ".join([f"{x:.2f}" for x in wesn]))
16281614
0.00, 10.00, -20.00, -10.00
16291615
16301616
Using ISO country codes for the regions (for example ``"US.HI"`` for
16311617
Hawaiʻi):
16321618
16331619
>>> fig = pygmt.Figure()
1634-
>>> fig.coast(
1635-
... region="US.HI", projection="M6i", frame=True, land="black"
1636-
... )
1620+
>>> fig.coast(region="US.HI", projection="M6i", frame=True, land="black")
16371621
>>> with Session() as lib:
16381622
... wesn = lib.extract_region()
1639-
...
16401623
>>> print(", ".join([f"{x:.2f}" for x in wesn]))
16411624
-164.71, -154.81, 18.91, 23.58
16421625
@@ -1645,12 +1628,9 @@ def extract_region(self):
16451628
region to multiples of 5):
16461629
16471630
>>> fig = pygmt.Figure()
1648-
>>> fig.coast(
1649-
... region="US.HI+r5", projection="M6i", frame=True, land="black"
1650-
... )
1631+
>>> fig.coast(region="US.HI+r5", projection="M6i", frame=True, land="black")
16511632
>>> with Session() as lib:
16521633
... wesn = lib.extract_region()
1653-
...
16541634
>>> print(", ".join([f"{x:.2f}" for x in wesn]))
16551635
-165.00, -150.00, 15.00, 25.00
16561636
""" # noqa: RUF002

pygmt/datasets/earth_free_air_anomaly.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def load_earth_free_air_anomaly(
9292
>>> # load the default grid (gridline-registered 1 arc-degree grid)
9393
>>> grid = load_earth_free_air_anomaly()
9494
>>> # load the 30 arc-minutes grid with "gridline" registration
95-
>>> grid = load_earth_free_air_anomaly(
96-
... resolution="30m", registration="gridline"
97-
... )
95+
>>> grid = load_earth_free_air_anomaly(resolution="30m", registration="gridline")
9896
>>> # load high-resolution (5 arc-minutes) grid for a specific region
9997
>>> grid = load_earth_free_air_anomaly(
10098
... resolution="05m",

pygmt/datasets/earth_magnetic_anomaly.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def load_earth_magnetic_anomaly(
119119
>>> # load the default grid (gridline-registered 1 arc-degree grid)
120120
>>> grid = load_earth_magnetic_anomaly()
121121
>>> # load the 30 arc-minutes grid with "gridline" registration
122-
>>> grid = load_earth_magnetic_anomaly(
123-
... resolution="30m", registration="gridline"
124-
... )
122+
>>> grid = load_earth_magnetic_anomaly(resolution="30m", registration="gridline")
125123
>>> # load high-resolution (5 arc-minutes) grid for a specific region
126124
>>> grid = load_earth_magnetic_anomaly(
127125
... resolution="05m",

pygmt/helpers/decorators.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ def fmt_docstring(module_func):
421421
... {aliases}
422422
... '''
423423
... pass
424-
...
425424
>>> print(gmtinfo.__doc__)
426425
<BLANKLINE>
427426
My nice module.
@@ -526,7 +525,6 @@ def use_alias(**aliases):
526525
>>> @use_alias(R="region", J="projection")
527526
... def my_module(**kwargs):
528527
... print("R =", kwargs["R"], "J =", kwargs["J"])
529-
...
530528
>>> my_module(R="bla", J="meh")
531529
R = bla J = meh
532530
>>> my_module(region="bla", J="meh")
@@ -641,9 +639,7 @@ def kwargs_to_strings(**conversions):
641639
642640
Examples
643641
--------
644-
>>> @kwargs_to_strings(
645-
... R="sequence", i="sequence_comma", files="sequence_space"
646-
... )
642+
>>> @kwargs_to_strings(R="sequence", i="sequence_comma", files="sequence_space")
647643
... def module(*args, **kwargs):
648644
... "A module that prints the arguments it received"
649645
... print("{", end="")
@@ -813,7 +809,6 @@ def deprecate_parameter(oldname, newname, deprecate_version, remove_version):
813809
... def module(data, size=0, **kwargs):
814810
... "A module that prints the arguments it received"
815811
... print(f"data={data}, size={size}, color={kwargs['color']}")
816-
...
817812
>>> # new names are supported
818813
>>> module(data="table.txt", size=5.0, color="red")
819814
data=table.txt, size=5.0, color=red
@@ -825,13 +820,11 @@ def deprecate_parameter(oldname, newname, deprecate_version, remove_version):
825820
... for i in range(len(w)):
826821
... assert issubclass(w[i].category, FutureWarning)
827822
... assert "deprecated" in str(w[i].message)
828-
...
829823
data=table.txt, size=5.0, color=red
830824
>>> # using both old and new names will raise an GMTInvalidInput exception
831825
>>> import pytest
832826
>>> with pytest.raises(GMTInvalidInput):
833827
... module(data="table.txt", size=5.0, sizes=4.0)
834-
...
835828
"""
836829

837830
def deprecator(module_func):

0 commit comments

Comments
 (0)