Skip to content

Commit b4ebdf2

Browse files
authored
fmt_docstrings: Use string template syntax for docstring placeholders and support curly braces in docstrings (#4210)
* fmt_docstrings: Use string.Template for docstring placeholders * Update docstring placeholders to the string.Template syntax * Update {aliases} to $aliases and {table-classes} to $table_classes * Replace {{/}} with {/} in LaTeX math equations
1 parent f9f343d commit b4ebdf2

Some content is hidden

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

57 files changed

+613
-613
lines changed

pygmt/helpers/decorators.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import functools
9+
import string
910
import textwrap
1011
import warnings
1112
from inspect import Parameter, signature
@@ -410,11 +411,11 @@ def fmt_docstring(module_func):
410411
... ----------
411412
... data
412413
... Pass in either a file name to an ASCII data table, a 2-D
413-
... {table-classes}.
414-
... {region}
415-
... {projection}
414+
... $table_classes.
415+
... $region
416+
... $projection
416417
...
417-
... {aliases}
418+
... $aliases
418419
... '''
419420
... pass
420421
>>> print(gmtinfo.__doc__)
@@ -456,7 +457,7 @@ def fmt_docstring(module_func):
456457
aliases.append(f" - {arg} = {alias}")
457458
filler_text["aliases"] = "\n".join(aliases)
458459

459-
filler_text["table-classes"] = (
460+
filler_text["table_classes"] = (
460461
":class:`numpy.ndarray`, a :class:`pandas.DataFrame`, an\n"
461462
" :class:`xarray.Dataset` made up of 1-D :class:`xarray.DataArray`\n"
462463
" data variables, or a :class:`geopandas.GeoDataFrame` containing the\n"
@@ -471,8 +472,7 @@ def fmt_docstring(module_func):
471472
# Dedent the docstring to make it all match the option text.
472473
docstring = textwrap.dedent(module_func.__doc__)
473474

474-
module_func.__doc__ = docstring.format(**filler_text)
475-
475+
module_func.__doc__ = string.Template(docstring).safe_substitute(**filler_text)
476476
return module_func
477477

478478

pygmt/src/basemap.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def basemap(
4545
4646
Full GMT docs at :gmt-docs:`basemap.html`.
4747
48-
{aliases}
48+
$aliases
4949
- B = frame
5050
- J = projection
5151
- Jz = zscale
@@ -58,12 +58,12 @@ def basemap(
5858
5959
Parameters
6060
----------
61-
{projection}
61+
$projection
6262
zscale/zsize
6363
Set z-axis scaling or z-axis size.
64-
{region}
64+
$region
6565
*Required if this is the first plot command.*
66-
{frame}
66+
$frame
6767
map_scale : str
6868
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\
6969
**+w**\ *length*.
@@ -92,11 +92,11 @@ def basemap(
9292
compass : str
9393
Draw a map magnetic rose on the map at the location defined by the
9494
reference and anchor points.
95-
{verbose}
96-
{panel}
97-
{coltypes}
98-
{perspective}
99-
{transparency}
95+
$verbose
96+
$panel
97+
$coltypes
98+
$perspective
99+
$transparency
100100
"""
101101
self._activate_figure()
102102

pygmt/src/binstats.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def binstats(
6565
6666
Full GMT docs at :gmt-docs:`gmtbinstats.html`.
6767
68-
{aliases}
68+
$aliases
6969
- C = statistic
7070
- I = spacing
7171
- R = region
@@ -76,8 +76,8 @@ def binstats(
7676
Parameters
7777
----------
7878
data
79-
A file name of an ASCII data table or a 2-D {table-classes}.
80-
{outgrid}
79+
A file name of an ASCII data table or a 2-D $table_classes.
80+
$outgrid
8181
statistic
8282
Choose the statistic that will be computed per node based on the points that are
8383
within *radius* distance of the node. Select one of:
@@ -116,14 +116,14 @@ def binstats(
116116
computed while the count will be the sum of the weights instead of
117117
number of points. If the weights are actually uncertainties
118118
(one sigma) then append **+s** and weight = 1/sigma.
119-
{spacing}
120-
{region}
121-
{verbose}
122-
{aspatial}
123-
{binary}
124-
{header}
125-
{incols}
126-
{registration}
119+
$spacing
120+
$region
121+
$verbose
122+
$aspatial
123+
$binary
124+
$header
125+
$incols
126+
$registration
127127
128128
Returns
129129
-------

pygmt/src/blockm.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def blockmean( # noqa: PLR0913
111111
112112
Full GMT docs at :gmt-docs:`blockmean.html`.
113113
114-
{aliases}
114+
$aliases
115115
- I = spacing
116116
- R = region
117117
- V = verbose
@@ -124,12 +124,12 @@ def blockmean( # noqa: PLR0913
124124
data
125125
Pass in (x, y, z) or (longitude, latitude, elevation) values by
126126
providing a file name to an ASCII data table, a 2-D
127-
{table-classes}.
127+
$table_classes.
128128
x/y/z : 1-D arrays
129129
Arrays of x and y coordinates and values z of the data points.
130-
{output_type}
131-
{outfile}
132-
{spacing}
130+
$output_type
131+
$outfile
132+
$spacing
133133
summary : str
134134
[**m**\|\ **n**\|\ **s**\|\ **w**].
135135
Type of summary values calculated by blockmean.
@@ -138,18 +138,18 @@ def blockmean( # noqa: PLR0913
138138
- **n**: report the number of input points inside each block
139139
- **s**: report the sum of all z-values inside a block
140140
- **w**: report the sum of weights
141-
{region}
142-
{verbose}
143-
{aspatial}
144-
{binary}
145-
{nodata}
146-
{find}
147-
{incols}
148-
{coltypes}
149-
{header}
150-
{outcols}
151-
{registration}
152-
{wrap}
141+
$region
142+
$verbose
143+
$aspatial
144+
$binary
145+
$nodata
146+
$find
147+
$incols
148+
$coltypes
149+
$header
150+
$outcols
151+
$registration
152+
$wrap
153153
154154
Returns
155155
-------
@@ -226,7 +226,7 @@ def blockmedian( # noqa: PLR0913
226226
227227
Full GMT docs at :gmt-docs:`blockmedian.html`.
228228
229-
{aliases}
229+
$aliases
230230
- I = spacing
231231
- R = region
232232
- V = verbose
@@ -239,24 +239,24 @@ def blockmedian( # noqa: PLR0913
239239
data
240240
Pass in (x, y, z) or (longitude, latitude, elevation) values by
241241
providing a file name to an ASCII data table, a 2-D
242-
{table-classes}.
242+
$table_classes.
243243
x/y/z : 1-D arrays
244244
Arrays of x and y coordinates and values z of the data points.
245-
{output_type}
246-
{outfile}
247-
{spacing}
248-
{region}
249-
{verbose}
250-
{aspatial}
251-
{binary}
252-
{nodata}
253-
{find}
254-
{coltypes}
255-
{header}
256-
{incols}
257-
{outcols}
258-
{registration}
259-
{wrap}
245+
$output_type
246+
$outfile
247+
$spacing
248+
$region
249+
$verbose
250+
$aspatial
251+
$binary
252+
$nodata
253+
$find
254+
$coltypes
255+
$header
256+
$incols
257+
$outcols
258+
$registration
259+
$wrap
260260
261261
Returns
262262
-------
@@ -341,7 +341,7 @@ def blockmode( # noqa: PLR0913
341341
342342
Full GMT docs at :gmt-docs:`blockmode.html`.
343343
344-
{aliases}
344+
$aliases
345345
- I = spacing
346346
- R = region
347347
- V = verbose
@@ -354,24 +354,24 @@ def blockmode( # noqa: PLR0913
354354
data
355355
Pass in (x, y, z) or (longitude, latitude, elevation) values by
356356
providing a file name to an ASCII data table, a 2-D
357-
{table-classes}.
357+
$table_classes.
358358
x/y/z : 1-D arrays
359359
Arrays of x and y coordinates and values z of the data points.
360-
{output_type}
361-
{outfile}
362-
{spacing}
363-
{region}
364-
{verbose}
365-
{aspatial}
366-
{binary}
367-
{nodata}
368-
{find}
369-
{coltypes}
370-
{header}
371-
{incols}
372-
{outcols}
373-
{registration}
374-
{wrap}
360+
$output_type
361+
$outfile
362+
$spacing
363+
$region
364+
$verbose
365+
$aspatial
366+
$binary
367+
$nodata
368+
$find
369+
$coltypes
370+
$header
371+
$incols
372+
$outcols
373+
$registration
374+
$wrap
375375
376376
Returns
377377
-------

pygmt/src/coast.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def coast(
6666
6767
Full GMT docs at :gmt-docs:`coast.html`.
6868
69-
{aliases}
69+
$aliases
7070
- B = frame
7171
- D = resolution
7272
- F = box
@@ -79,11 +79,11 @@ def coast(
7979
8080
Parameters
8181
----------
82-
{projection}
83-
{region}
82+
$projection
83+
$region
8484
*Required if this is the first plot command.*
85-
{area_thresh}
86-
{frame}
85+
$area_thresh
86+
$frame
8787
lakes : str or list
8888
*fill*\ [**+l**\|\ **+r**].
8989
Set the shade, color, or pattern for lakes and river-lakes. The
@@ -172,10 +172,10 @@ def coast(
172172
to any of the continent codes (e.g. ``"=EU"`` for Europe). Append
173173
**+p**\ *pen* to draw polygon outlines [Default is no outline] and
174174
**+g**\ *fill* to fill them [Default is no fill].
175-
{panel}
176-
{perspective}
177-
{transparency}
178-
{verbose}
175+
$panel
176+
$perspective
177+
$transparency
178+
$verbose
179179
180180
Example
181181
-------

pygmt/src/colorbar.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def colorbar( # noqa: PLR0913
4444
.. note::
4545
For GMT >=6.5.0, the fontsizes of the colorbar x-label, x-annotations,
4646
and y-label are scaled based on the width of the colorbar following
47-
:math:`\sqrt{{colorbar\_width / 15}}`. To set a desired fontsize via the
47+
:math:`\sqrt{colorbar\_width / 15}`. To set a desired fontsize via the
4848
GMT default parameters :gmt-term:`FONT_ANNOT_PRIMARY`,
4949
:gmt-term:`FONT_ANNOT_SECONDARY`, and :gmt-term:`FONT_LABEL` (or jointly
5050
:gmt-term:`FONT`) users have to divide the desired fontsize by the value
@@ -54,7 +54,7 @@ def colorbar( # noqa: PLR0913
5454
5555
Full GMT docs at :gmt-docs:`colorbar.html`.
5656
57-
{aliases}
57+
$aliases
5858
- B = frame
5959
- F = box
6060
- G = truncate
@@ -70,7 +70,7 @@ def colorbar( # noqa: PLR0913
7070
----------
7171
frame : str or list
7272
Set colorbar boundary frame, labels, and axes attributes.
73-
{cmap}
73+
$cmap
7474
position : str
7575
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\
7676
[**+w**\ *length*\ [/\ *width*]]\ [**+e**\ [**b**\|\ **f**][*length*]]\
@@ -134,10 +134,10 @@ def colorbar( # noqa: PLR0913
134134
may be in plot distance units or given as relative fractions and will
135135
be automatically scaled so that the sum of the widths equals the
136136
requested colorbar length.
137-
{verbose}
138-
{panel}
139-
{perspective}
140-
{transparency}
137+
$verbose
138+
$panel
139+
$perspective
140+
$transparency
141141
142142
Example
143143
-------

0 commit comments

Comments
 (0)