Skip to content

Commit b73fe9e

Browse files
committed
Convert docstring snippets dict to _SnippetsManager class
1 parent 35c9123 commit b73fe9e

File tree

17 files changed

+418
-414
lines changed

17 files changed

+418
-414
lines changed

proplot/axes/base.py

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_pop_kwargs,
3636
_pop_params,
3737
_pop_props,
38+
_snippet_manager,
3839
_version_mpl,
3940
docstring,
4041
rcsetup,
@@ -64,7 +65,7 @@
6465
`~matplotlib.axes.Axes.transAxes`, or `~matplotlib.figure.Figure.transFigure`
6566
transforms. Default is ``'axes'``, i.e. `bounds` is in axes-relative coordinates.
6667
"""
67-
docstring.snippets['axes.transform'] = _transform_docstring
68+
_snippet_manager['axes.transform'] = _transform_docstring
6869

6970

7071
# Projection docstring
@@ -89,9 +90,9 @@
8990
Whether to use `~mpl_toolkits.basemap.Basemap` or `~cartopy.crs.Projection`
9091
for map projections. Default is :rc:`basemap`.
9192
"""
92-
docstring.snippets['axes.proj'] = _proj_docstring
93-
docstring.snippets['axes.proj_kw'] = _proj_kw_docstring
94-
docstring.snippets['axes.basemap'] = _basemap_docstring
93+
_snippet_manager['axes.proj'] = _proj_docstring
94+
_snippet_manager['axes.proj_kw'] = _proj_kw_docstring
95+
_snippet_manager['axes.basemap'] = _basemap_docstring
9596

9697

9798
# Inset docstring
@@ -125,7 +126,7 @@
125126
**kwargs
126127
Passed to `CartesianAxes`.
127128
"""
128-
docstring.snippets['axes.inset'] = docstring.add_snippets(_inset_docstring)
129+
_snippet_manager['axes.inset'] = _inset_docstring
129130

130131

131132
# Panel docstring
@@ -168,7 +169,7 @@
168169
`~proplot.axes.CartesianAxes`
169170
The panel axes.
170171
"""
171-
docstring.snippets['axes.panel'] = docstring.add_snippets(_panel_docstring)
172+
_snippet_manager['axes.panel'] = _panel_docstring
172173

173174

174175
# Colorbar and legend space
@@ -191,11 +192,11 @@
191192
*inset* {name}, the old {name} is removed. If ``False`` and `loc` is an
192193
*outer* {name}, the {name}s are stacked.
193194
"""
194-
docstring.snippets['axes.legend_space'] = docstring.add_snippets(
195-
_space_docstring.format(name='legend', default='legend.borderaxespad')
195+
_snippet_manager['axes.legend_space'] = _space_docstring.format(
196+
name='legend', default='legend.borderaxespad'
196197
)
197-
docstring.snippets['axes.colorbar_space'] = docstring.add_snippets(
198-
_space_docstring.format(name='colorbar', default='colorbar.insetpad')
198+
_snippet_manager['axes.colorbar_space'] = _space_docstring.format(
199+
name='colorbar', default='colorbar.insetpad'
199200
)
200201

201202

@@ -302,9 +303,9 @@
302303
Many of the keyword arguments documented above are actually applied by updating
303304
the `~proplot.config.rc` settings then retrieving the updated settings.
304305
"""
305-
docstring.snippets['axes.rc'] = _rc_format_docstring
306-
docstring.snippets['axes.format'] = _axes_format_docstring
307-
docstring.snippets['figure.format'] = _figure_format_docstring
306+
_snippet_manager['axes.rc'] = _rc_format_docstring
307+
_snippet_manager['axes.format'] = _axes_format_docstring
308+
_snippet_manager['figure.format'] = _figure_format_docstring
308309

309310

310311
# Colorbar docstrings
@@ -344,8 +345,8 @@
344345
mappable object. If the attribute is unavailable, we use ``'neither'``.
345346
extendsize : float or str, optional
346347
The length of the colorbar "extensions" in physical units. Default is
347-
:rc:`colorbar.insetextend` for inset colorbars and :rc:`colorbar.extend`
348-
for outer colorbars. %(units.em)s
348+
:rc:`colorbar.insetextend` for inset colorbars and :rc:`colorbar.extend` for
349+
outer colorbars. %(units.em)s
349350
frame, frameon : bool, optional
350351
For inset colorbars only. Indicates whether to draw a "frame", just
351352
like `~matplotlib.axes.Axes.legend`. Default is :rc:`colorbar.frameon`.
@@ -411,8 +412,8 @@
411412
**kwargs
412413
Passed to `~matplotlib.figure.Figure.colorbar`.
413414
"""
414-
docstring.snippets['axes.colorbar_args'] = _colorbar_args_docstring
415-
docstring.snippets['axes.colorbar_kwargs'] = _colorbar_kwargs_docstring
415+
_snippet_manager['axes.colorbar_args'] = _colorbar_args_docstring
416+
_snippet_manager['axes.colorbar_kwargs'] = _colorbar_kwargs_docstring
416417

417418

418419
# Legend docstrings
@@ -476,8 +477,8 @@
476477
**kwargs
477478
Passed to `~matplotlib.axes.Axes.legend`.
478479
"""
479-
docstring.snippets['axes.legend_args'] = _legend_args_docstring
480-
docstring.snippets['axes.legend_kwargs'] = _legend_kwargs_docstring
480+
_snippet_manager['axes.legend_args'] = _legend_args_docstring
481+
_snippet_manager['axes.legend_kwargs'] = _legend_kwargs_docstring
481482

482483

483484
class Axes(maxes.Axes):
@@ -1234,8 +1235,8 @@ def _update_super_labels(self, side, labels=None, **kwargs):
12341235
if labels or kw:
12351236
fig._update_super_labels(side, labels, **kw)
12361237

1237-
@docstring.obfuscate_signature
1238-
@docstring.add_snippets
1238+
@docstring._obfuscate_signature
1239+
@_snippet_manager
12391240
def format(
12401241
self, *, title=None, title_kw=None, abc_kw=None,
12411242
ltitle=None, lefttitle=None,
@@ -1378,14 +1379,14 @@ def get_tightbbox(self, renderer, *args, **kwargs):
13781379
self._tight_bbox = bbox
13791380
return bbox
13801381

1381-
@docstring.add_snippets
1382+
@_snippet_manager
13821383
def inset(self, *args, **kwargs):
13831384
"""
13841385
%(axes.inset)s
13851386
"""
13861387
return self.inset_axes(*args, **kwargs)
13871388

1388-
@docstring.add_snippets
1389+
@_snippet_manager
13891390
def inset_axes(
13901391
self, bounds, transform=None, *, proj=None, projection=None,
13911392
zoom=None, zoom_kw=None, zorder=4, **kwargs
@@ -1486,14 +1487,14 @@ def indicate_inset_zoom(self, **kwargs):
14861487
self._inset_zoom_data = (rectpatch, connects)
14871488
return rectpatch, connects
14881489

1489-
@docstring.add_snippets
1490+
@_snippet_manager
14901491
def panel(self, *args, **kwargs):
14911492
"""
14921493
%(axes.panel)s
14931494
"""
14941495
return self.panel_axes(*args, **kwargs)
14951496

1496-
@docstring.add_snippets
1497+
@_snippet_manager
14971498
def panel_axes(self, *args, **kwargs):
14981499
"""
14991500
%(axes.panel)s
@@ -2187,8 +2188,8 @@ def _draw_colorbar(
21872188
self._add_guide('colorbar', obj, loc) # possibly replace another
21882189
return obj
21892190

2190-
@docstring.obfuscate_signature
2191-
@docstring.add_snippets
2191+
@docstring._obfuscate_signature
2192+
@_snippet_manager
21922193
def colorbar(
21932194
self, mappable, values=None, *, loc=None, location=None, queue=False,
21942195
**kwargs
@@ -2701,8 +2702,8 @@ def _draw_legend(
27012702
self._add_guide('legend', obj, loc) # possibly replace another
27022703
return obj
27032704

2704-
@docstring.concatenate_original
2705-
@docstring.add_snippets
2705+
@docstring._concatenate_original
2706+
@_snippet_manager
27062707
def legend(
27072708
self, handles=None, labels=None, *, loc=None, location=None, queue=False,
27082709
**kwargs
@@ -2838,7 +2839,8 @@ def _update_text(text, props=None, **kwargs):
28382839

28392840
return mtext.Text.update(text, props)
28402841

2841-
@docstring.concatenate_original
2842+
@docstring._concatenate_original
2843+
@_snippet_manager
28422844
def text(
28432845
self, *args,
28442846
border=False, bordercolor='w', borderwidth=2, borderinvert=False,
@@ -2883,15 +2885,17 @@ def text(
28832885
The alpha for the bounding box. Default is ``'0.5'``.
28842886
bboxpad : float, optional
28852887
The padding for the bounding box. Default is :rc:`title.bboxpad`.
2886-
family, fontfamily, name, fontname : str, optional
2887-
The font name (e.g., ``'Fira Math'``) or font family name (e.g.,
2888+
name, fontname
2889+
Aliases for `family`, `fontfamily`.
2890+
family, fontfamily : str, optional
2891+
The font typeface name (e.g., ``'Fira Math'``) or font family name (e.g.,
28882892
``'serif'``). Matplotlib falls back to the system default if not found.
28892893
size, fontsize : float or str, optional
28902894
The font size. %(units.pt)s
28912895
This can also be a string indicating some scaling relative to
2892-
:rcraw:`font.size`. The sizes and scalings are shown below.
2893-
``'med-small'`` and ``'med-large'`` are added by ProPlot
2894-
while the rest are native matplotlib sizes.
2896+
:rcraw:`font.size`. The sizes and scalings are shown below. The
2897+
scalings ``'med'``, ``'med-small'``, and ``'med-large'`` are
2898+
added by ProPlot while the rest are native matplotlib sizes.
28952899
28962900
.. _font_table:
28972901

proplot/axes/cartesian.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .. import ticker as pticker
1212
from ..config import _parse_format, rc
1313
from ..internals import ic # noqa: F401
14-
from ..internals import _not_none, docstring, rcsetup, warnings
14+
from ..internals import _not_none, _snippet_manager, docstring, rcsetup, warnings
1515
from . import plot, shared
1616

1717
__all__ = ['CartesianAxes']
@@ -51,7 +51,7 @@
5151
{args} : optional
5252
Prepended with ``'{x}'`` and passed to `Axes.format`.
5353
"""
54-
docstring.snippets['axes.altx'] = _alt_doc.format(
54+
_snippet_manager['axes.altx'] = _alt_doc.format(
5555
x='x',
5656
x1='bottom',
5757
x2='top',
@@ -61,7 +61,7 @@
6161
args=', '.join(_alt_kwargs),
6262
xargs=', '.join('x' + key for key in _alt_kwargs),
6363
)
64-
docstring.snippets['axes.alty'] = _alt_doc.format(
64+
_snippet_manager['axes.alty'] = _alt_doc.format(
6565
x='y',
6666
x1='left',
6767
x2='right',
@@ -88,12 +88,12 @@
8888
{args} : optional
8989
Prepended with ``'{x}'`` and passed to `Axes.format`.
9090
"""
91-
docstring.snippets['axes.dualx'] = _dual_doc.format(
91+
_snippet_manager['axes.dualx'] = _dual_doc.format(
9292
x='x',
9393
args=', '.join(_alt_kwargs),
9494
xargs=', '.join('x' + key for key in _alt_kwargs),
9595
)
96-
docstring.snippets['axes.dualy'] = _dual_doc.format(
96+
_snippet_manager['axes.dualy'] = _dual_doc.format(
9797
x='y',
9898
args=', '.join(_alt_kwargs),
9999
xargs=', '.join('y' + key for key in _alt_kwargs),
@@ -120,13 +120,13 @@
120120
{args} : optional
121121
Prepended with ``'{x}'`` and passed to `Axes.format`.
122122
"""
123-
docstring.snippets['axes.twinx'] = _twin_doc.format(
123+
_snippet_manager['axes.twinx'] = _twin_doc.format(
124124
x='y', x1='left', x2='right',
125125
y='x', y1='bottom', y2='top',
126126
args=', '.join(_alt_kwargs),
127127
xargs=', '.join('y' + key for key in _alt_kwargs),
128128
)
129-
docstring.snippets['axes.twiny'] = _twin_doc.format(
129+
_snippet_manager['axes.twiny'] = _twin_doc.format(
130130
x='x', x1='bottom', x2='top',
131131
y='y', y1='left', y2='right',
132132
args=', '.join(_alt_kwargs),
@@ -651,8 +651,8 @@ def _update_locs(self, x, *, tickloc=None, ticklabelloc=None, labelloc=None):
651651
if labelloc is not None:
652652
getattr(self, x + 'axis').set_label_position(labelloc)
653653

654-
@docstring.obfuscate_signature
655-
@docstring.add_snippets
654+
@docstring._obfuscate_signature
655+
@_snippet_manager
656656
def format(
657657
self, *,
658658
aspect=None,
@@ -1006,7 +1006,7 @@ def format(
10061006
self.set_aspect(aspect)
10071007
super().format(rc_kw=rc_kw, rc_mode=rc_mode, **kwargs)
10081008

1009-
@docstring.add_snippets
1009+
@_snippet_manager
10101010
def altx(self, **kwargs):
10111011
"""
10121012
%(axes.altx)s
@@ -1058,7 +1058,7 @@ def altx(self, **kwargs):
10581058

10591059
return ax
10601060

1061-
@docstring.add_snippets
1061+
@_snippet_manager
10621062
def alty(self, **kwargs):
10631063
"""
10641064
%(axes.alty)s
@@ -1096,7 +1096,7 @@ def alty(self, **kwargs):
10961096

10971097
return ax
10981098

1099-
@docstring.add_snippets
1099+
@_snippet_manager
11001100
def dualx(self, funcscale, **kwargs):
11011101
"""
11021102
%(axes.dualx)s
@@ -1109,7 +1109,7 @@ def dualx(self, funcscale, **kwargs):
11091109
ax._dualx_scale()
11101110
return ax
11111111

1112-
@docstring.add_snippets
1112+
@_snippet_manager
11131113
def dualy(self, funcscale, **kwargs):
11141114
"""
11151115
%(axes.dualy)s
@@ -1120,14 +1120,14 @@ def dualy(self, funcscale, **kwargs):
11201120
ax._dualy_scale()
11211121
return ax
11221122

1123-
@docstring.add_snippets
1123+
@_snippet_manager
11241124
def twinx(self):
11251125
"""
11261126
%(axes.twinx)s
11271127
"""
11281128
return self.alty()
11291129

1130-
@docstring.add_snippets
1130+
@_snippet_manager
11311131
def twiny(self):
11321132
"""
11331133
%(axes.twiny)s

proplot/axes/geo.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
from .. import crs as pcrs
1515
from ..config import _parse_format, rc
1616
from ..internals import ic # noqa: F401
17-
from ..internals import _not_none, _version_cartopy, docstring, warnings
17+
from ..internals import (
18+
_not_none,
19+
_snippet_manager,
20+
_version_cartopy,
21+
docstring,
22+
warnings,
23+
)
1824
from . import plot
1925

2026
try:
@@ -365,8 +371,8 @@ def _to_label_array(labels, lon=True):
365371

366372
return array
367373

368-
@docstring.obfuscate_signature
369-
@docstring.add_snippets
374+
@docstring._obfuscate_signature
375+
@_snippet_manager
370376
def format(
371377
self, *,
372378
lonlim=None, latlim=None, boundinglat=None,

0 commit comments

Comments
 (0)