Skip to content

Commit 401b4f4

Browse files
committed
Fix config and psconvert
1 parent 8c0785e commit 401b4f4

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

pygmt/figure.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pygmt.clib import Session
1919
from pygmt.exceptions import GMTError, GMTInvalidInput
2020
from pygmt.helpers import (
21-
build_arg_string,
21+
build_arg_list,
2222
fmt_docstring,
2323
kwargs_to_strings,
2424
launch_external_viewer,
@@ -234,15 +234,12 @@ def psconvert(self, **kwargs):
234234
# Default cropping the figure to True
235235
if kwargs.get("A") is None:
236236
kwargs["A"] = ""
237-
# Manually handle prefix -F argument so spaces aren't converted to \040
238-
# by build_arg_string function. For more information, see
239-
# https://github.com/GenericMappingTools/pygmt/pull/1487
240-
prefix = kwargs.pop("F", None)
237+
238+
prefix = kwargs.get("F")
241239
if prefix in ["", None, False, True]:
242240
raise GMTInvalidInput(
243241
"The 'prefix' parameter must be specified with a valid value."
244242
)
245-
prefix_arg = f'-F"{prefix}"'
246243

247244
# check if the parent directory exists
248245
prefix_path = Path(prefix).parent
@@ -252,9 +249,7 @@ def psconvert(self, **kwargs):
252249
)
253250

254251
with Session() as lib:
255-
lib.call_module(
256-
module="psconvert", args=f"{prefix_arg} {build_arg_string(kwargs)}"
257-
)
252+
lib.call_module(module="psconvert", args=build_arg_list(kwargs))
258253

259254
def savefig( # noqa: PLR0912
260255
self,

pygmt/src/config.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ def __init__(self, **kwargs):
199199
self.old_defaults[key] = lib.get_default(key)
200200

201201
# call gmt set to change GMT defaults
202-
arg_str = " ".join([f'{key}="{value}"' for key, value in kwargs.items()])
203202
with Session() as lib:
204-
lib.call_module(module="set", args=arg_str)
203+
lib.call_module(
204+
module="set", args=[f"{key}={value}" for key, value in kwargs.items()]
205+
)
205206

206207
def __enter__(self):
207208
"""
@@ -213,8 +214,8 @@ def __exit__(self, exc_type, exc_value, traceback):
213214
"""
214215
Revert GMT configurations to initial values.
215216
"""
216-
arg_str = " ".join(
217-
[f'{key}="{value}"' for key, value in self.old_defaults.items()]
218-
)
219217
with Session() as lib:
220-
lib.call_module(module="set", args=arg_str)
218+
lib.call_module(
219+
module="set",
220+
args=[f"{key}={value}" for key, value in self.old_defaults.items()],
221+
)

0 commit comments

Comments
 (0)