@@ -629,31 +629,29 @@ def call_module(self, module: str, args: str | list[str]):
629
629
630
630
# 'args' can be (1) a single string or (2) a list of strings.
631
631
argv : bytes | ctp .Array [ctp .c_char_p ] | None
632
- if isinstance (args , str ):
633
- # 'args' is a single string that contains whitespace-separated arguments.
634
- # In this way, we need to correctly handle option arguments that contain
635
- # whitespaces or quotation marks. It's used in PyGMT <= v0.11.0 but is no
636
- # longer recommended.
637
- mode = self ["GMT_MODULE_CMD" ]
638
- argv = args .encode ()
639
- elif isinstance (args , list ):
632
+ if isinstance (args , list ):
640
633
# 'args' is a list of strings and each string contains a module argument.
641
634
# In this way, GMT can correctly handle option arguments with whitespaces or
642
635
# quotation marks. This is the preferred way to pass arguments to the GMT
643
636
# API and is used for PyGMT >= v0.12.0.
644
637
mode = len (args ) # 'mode' is the number of arguments.
645
638
# Pass a null pointer if no arguments are specified.
646
639
argv = strings_to_ctypes_array (args ) if mode != 0 else None
640
+ elif isinstance (args , str ):
641
+ # 'args' is a single string that contains whitespace-separated arguments.
642
+ # In this way, we need to correctly handle option arguments that contain
643
+ # whitespaces or quotation marks. It's used in PyGMT <= v0.11.0 but is no
644
+ # longer recommended.
645
+ mode = self ["GMT_MODULE_CMD" ]
646
+ argv = args .encode ()
647
647
else :
648
- raise GMTInvalidInput (
649
- "'args' must be either a string or a list of strings."
650
- )
648
+ msg = "'args' must either be a list of strings (recommended) or a string."
649
+ raise GMTInvalidInput (msg )
651
650
652
651
status = c_call_module (self .session_pointer , module .encode (), mode , argv )
653
652
if status != 0 :
654
- raise GMTCLibError (
655
- f"Module '{ module } ' failed with status code { status } :\n { self ._error_message } "
656
- )
653
+ msg = f"Module '{ module } ' failed with status code { status } :\n { self ._error_message } "
654
+ raise GMTCLibError (msg )
657
655
658
656
def create_data (
659
657
self ,
0 commit comments