Repository: GenericMappingTools/pygmt

Issue:
PS_CONVERT has no effect when using Figure.show/Figure.savefig/Figure.psconvert
### Description of the problem

`PS_CONVERT` is a GMT configuration parameter that can store a comma-separate list of options to use when calling psconvert implicitely when `gmt end` is called. The GMT documentation is at https://docs.generic-mapping-tools.org/6.6/gmt.conf.html#term-PS_CONVERT.

> Comma-separated list of optional module arguments that we should supply when [psconvert](https://docs.generic-mapping-tools.org/6.6/psconvert.html) is called implicitly under modern mode [A]. Ignored when psconvert is called on the command line explicitly. The option arguments must be listed without their leading option hyphen.

In PyGMT, `Figure.show`/`Figure.savefig` calls `psconvert` internally, so this option has no effect, which is expected according to the GMT documentation. As a workaround, we can explicitely add these options when calling `Figure.show`/`Figure.savefig`, but it's a little tedious.

Possible solutions are:

1. Document that `PS_CONVERT` is ignored in PyGMT.
2. In `Figure.psconvert`, parse the values of `PS_CONVERT` and append them to the argument list when calling `psconvert`.
3. Thinking about if there is a more Pythonic and elegant way to implement the same feature.

Solution 2 is not that hard to implement, but need time to think about solution 3.

### Minimal Complete Verifiable Example

```python
import pygmt
pygmt.config(PS_CONVERT="C-I/home/xxx/.gmt")
fig = pygmt.Figure()
fig.basemap(region="g", projection="H8c", frame=True)
fig.savefig("map.png", verbose="d")
```

### Full error message

```python-traceback
pygmt-session [DEBUG]: Revised options: -A -Fmap -Qg2 -Qt2 -Tg -Vd
psconvert [DEBUG]: Ghostscript executable full name:
psconvert [DEBUG]: gmt_run_process_get_first_line: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Ghostscript version: 10.06.0
```
Options in `PS_CONVERT` are not shown in the first line of the debugging message.


_The bug was originally found in https://github.com/GenericMappingTools/pygmt/issues/3220._

Discussion:

Fix (patch):
diff --git a/pygmt/src/config.py b/pygmt/src/config.py
index 8b95fa8ed28..b1a042c3813 100644
--- a/pygmt/src/config.py
+++ b/pygmt/src/config.py
@@ -2,6 +2,7 @@
 config - Change GMT default settings globally or locally.
 """
 
+import warnings
 from inspect import Parameter, Signature
 from typing import ClassVar
 
@@ -22,6 +23,12 @@ class config:  # noqa: N801
             ...
 
     Full GMT defaults list at :gmt-docs:`gmt.conf.html`.
+
+    .. note::
+
+        :gmt-term:`PS_CONVERT` is not supported.
+        To configure conversion options, please pass parameters to
+        :meth:`pygmt.Figure.savefig` or :meth:`pygmt.Figure.show` instead.
     """
 
     # Manually set the __signature__ attribute to enable tab autocompletion
@@ -135,7 +142,7 @@ class config:  # noqa: N801
         "PS_CHAR_ENCODING",
         "PS_COLOR_MODEL",
         "PS_COMMENTS",
-        "PS_CONVERT",
+        # "PS_CONVERT",  # Not supported; use parameters of Figure.savefig/show instead
         "PS_IMAGE_COMPRESS",
         "PS_LINE_CAP",
         "PS_LINE_JOIN",
@@ -188,6 +195,16 @@ class config:  # noqa: N801
     )
 
     def __init__(self, **kwargs):
+        if "PS_CONVERT" in kwargs:
+            warnings.warn(
+                message="Parameter 'PS_CONVERT' is not supported. "
+                "To configure conversion options, please pass parameters to "
+                "pygmt.Figure.savefig or pygmt.Figure.show instead.",
+                category=SyntaxWarning,
+                stacklevel=2,
+            )
+            kwargs.pop("PS_CONVERT")
+
         # Save values so that we can revert to their initial values
         self.old_defaults = {}
         with Session() as lib:


Test changes:
diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py
index b946abeaea9..6a8c9bf3529 100644
--- a/pygmt/tests/test_config.py
+++ b/pygmt/tests/test_config.py
@@ -198,3 +198,20 @@ def test_config_map_tick_pen():
     fig.shift_origin(yshift=-3)
     fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error")
     return fig
+
+
+def test_config_ps_convert():
+    """
+    Test that Parameter 'PS_CONVERT' is not supported.
+    """
+    # Check that PS_CONVERT is removed from the autocomplete list
+    assert "PS_CONVERT" not in config._keywords
+
+    # Check that a warning is raised when PS_CONVERT is used in config
+    msg = (
+        "Parameter 'PS_CONVERT' is not supported. "
+        "To configure conversion options, please pass parameters to "
+        "pygmt.Figure.savefig or pygmt.Figure.show instead."
+    )
+    with pytest.warns(SyntaxWarning, match=msg):
+        config(PS_CONVERT="C")