@@ -212,11 +212,20 @@ def __enter__(self):
212
212
213
213
Calls :meth:`pygmt.clib.Session.create`.
214
214
"""
215
+ _init_cli_session = False
215
216
# This is the first time a Session object is created.
216
217
if _STATE ["session_name" ] is None :
217
218
# Set GMT_SESSION_NAME to a customized, unique value.
218
219
_STATE ["session_name" ] = os .environ ["GMT_SESSION_NAME" ] = unique_name ()
220
+ # Need to initialize the GMT CLI session.
221
+ _init_cli_session = True
219
222
self .create ("pygmt-session" )
223
+
224
+ if _init_cli_session :
225
+ self .call_module ("begin" , args = ["pygmt-session" ])
226
+ self .call_module (module = "set" , args = ["GMT_COMPATIBILITY=6" ])
227
+ del _init_cli_session
228
+
220
229
return self
221
230
222
231
def __exit__ (self , exc_type , exc_value , traceback ):
@@ -630,12 +639,6 @@ def call_module(self, module: str, args: str | list[str]):
630
639
GMTCLibError
631
640
If the returned status code of the function is non-zero.
632
641
"""
633
- if _STATE ["module_calls" ] is None :
634
- from pygmt .session_management import begin
635
-
636
- _STATE ["module_calls" ] = []
637
- begin ()
638
-
639
642
c_call_module = self .get_libgmt_func (
640
643
"GMT_Call_Module" ,
641
644
argtypes = [ctp .c_void_p , ctp .c_char_p , ctp .c_int , ctp .c_void_p ],
@@ -664,7 +667,6 @@ def call_module(self, module: str, args: str | list[str]):
664
667
"'args' must be either a string or a list of strings."
665
668
)
666
669
667
- _STATE ["module_calls" ].append (module )
668
670
status = c_call_module (self .session_pointer , module .encode (), mode , argv )
669
671
if status != 0 :
670
672
raise GMTCLibError (
0 commit comments