GeezerVison is showing github.com — Add a note/warning that PS_CONVERT is not supported (#4342) · GenericMappingTools/pygmt@cb42a3c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pygmt/src/config.py +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | config - Change GMT default settings globally or locally. | 3 | 3 | """ | 4 | 4 |
| | 5 | +import warnings | 5 | 6 | from inspect import Parameter, Signature | 6 | 7 | from typing import ClassVar | 7 | 8 |
| @@ -22,6 +23,12 @@ class config: # noqa: N801 | 22 | 23 | ... | 23 | 24 |
| 24 | 25 | Full GMT defaults list at :gmt-docs:`gmt.conf.html`. | | 26 | +
| | 27 | + .. note:: | | 28 | +
| | 29 | + :gmt-term:`PS_CONVERT` is not supported. | | 30 | + To configure conversion options, please pass parameters to | | 31 | + :meth:`pygmt.Figure.savefig` or :meth:`pygmt.Figure.show` instead. | 25 | 32 | """ | 26 | 33 |
| 27 | 34 | # Manually set the __signature__ attribute to enable tab autocompletion | @@ -135,7 +142,7 @@ class config: # noqa: N801 | 135 | 142 | "PS_CHAR_ENCODING", | 136 | 143 | "PS_COLOR_MODEL", | 137 | 144 | "PS_COMMENTS", | 138 | | - "PS_CONVERT", | | 145 | + # "PS_CONVERT", # Not supported; use parameters of Figure.savefig/show instead | 139 | 146 | "PS_IMAGE_COMPRESS", | 140 | 147 | "PS_LINE_CAP", | 141 | 148 | "PS_LINE_JOIN", | @@ -188,6 +195,16 @@ class config: # noqa: N801 | 188 | 195 | ) | 189 | 196 |
| 190 | 197 | def __init__(self, **kwargs): | | 198 | + if "PS_CONVERT" in kwargs: | | 199 | + warnings.warn( | | 200 | + message="Parameter 'PS_CONVERT' is not supported. " | | 201 | + "To configure conversion options, please pass parameters to " | | 202 | + "pygmt.Figure.savefig or pygmt.Figure.show instead.", | | 203 | + category=SyntaxWarning, | | 204 | + stacklevel=2, | | 205 | + ) | | 206 | + kwargs.pop("PS_CONVERT") | | 207 | + | 191 | 208 | # Save values so that we can revert to their initial values | 192 | 209 | self.old_defaults = {} | 193 | 210 | with Session() as lib: | |
Collapse file Copy file name to clipboardExpand all lines: pygmt/tests/test_config.py +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -198,3 +198,20 @@ def test_config_map_tick_pen(): | 198 | 198 | fig.shift_origin(yshift=-3) | 199 | 199 | fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error") | 200 | 200 | return fig | | 201 | + | | 202 | + | | 203 | +def test_config_ps_convert(): | | 204 | + """ | | 205 | + Test that Parameter 'PS_CONVERT' is not supported. | | 206 | + """ | | 207 | + # Check that PS_CONVERT is removed from the autocomplete list | | 208 | + assert "PS_CONVERT" not in config._keywords | | 209 | + | | 210 | + # Check that a warning is raised when PS_CONVERT is used in config | | 211 | + msg = ( | | 212 | + "Parameter 'PS_CONVERT' is not supported. " | | 213 | + "To configure conversion options, please pass parameters to " | | 214 | + "pygmt.Figure.savefig or pygmt.Figure.show instead." | | 215 | + ) | | 216 | + with pytest.warns(SyntaxWarning, match=msg): | | 217 | + config(PS_CONVERT="C") |
|