@@ -173,7 +173,8 @@ def session_pointer(self) -> ctp.c_void_p:
173
173
the context manager).
174
174
"""
175
175
if getattr (self , "_session_pointer" , None ) is None :
176
- raise GMTCLibNoSessionError ("No currently open GMT API session." )
176
+ msg = "No currently open GMT API session."
177
+ raise GMTCLibNoSessionError (msg )
177
178
return self ._session_pointer
178
179
179
180
@session_pointer .setter
@@ -276,7 +277,8 @@ def get_enum(self, name: str) -> int:
276
277
session = None
277
278
value = c_get_enum (session , name .encode ())
278
279
if value is None or value == - 99999 :
279
- raise GMTCLibError (f"Constant '{ name } ' doesn't exist in libgmt." )
280
+ msg = f"Constant '{ name } ' doesn't exist in libgmt."
281
+ raise GMTCLibError (msg )
280
282
return value
281
283
282
284
def get_libgmt_func (
@@ -558,7 +560,8 @@ def get_common(self, option: str) -> bool | int | float | np.ndarray:
558
560
pygmt.exceptions.GMTInvalidInput: Unknown GMT common option flag 'A'.
559
561
"""
560
562
if option not in "BIJRUVXYabfghinoprst:" :
561
- raise GMTInvalidInput (f"Unknown GMT common option flag '{ option } '." )
563
+ msg = f"Unknown GMT common option flag '{ option } '."
564
+ raise GMTInvalidInput (msg )
562
565
563
566
c_get_common = self .get_libgmt_func (
564
567
"GMT_Get_Common" ,
@@ -1194,7 +1197,8 @@ def read_data(
1194
1197
data ,
1195
1198
)
1196
1199
if data_ptr is None :
1197
- raise GMTCLibError (f"Failed to read dataset from '{ infile } '." )
1200
+ msg = f"Failed to read dataset from '{ infile } '."
1201
+ raise GMTCLibError (msg )
1198
1202
return ctp .cast (data_ptr , ctp .POINTER (dtype ))
1199
1203
1200
1204
def write_data (self , family , geometry , mode , wesn , output , data ):
@@ -1264,7 +1268,8 @@ def write_data(self, family, geometry, mode, wesn, output, data):
1264
1268
data ,
1265
1269
)
1266
1270
if status != 0 :
1267
- raise GMTCLibError (f"Failed to write dataset to '{ output } '" )
1271
+ msg = f"Failed to write dataset to '{ output } '."
1272
+ raise GMTCLibError (msg )
1268
1273
1269
1274
@contextlib .contextmanager
1270
1275
def open_virtualfile (
@@ -1856,9 +1861,8 @@ def virtualfile_in(
1856
1861
elif check_kind == "vector" :
1857
1862
valid_kinds += ("empty" , "matrix" , "vectors" , "geojson" )
1858
1863
if kind not in valid_kinds :
1859
- raise GMTInvalidInput (
1860
- f"Unrecognized data type for { check_kind } : { type (data )} "
1861
- )
1864
+ msg = f"Unrecognized data type for { check_kind } : { type (data )} ."
1865
+ raise GMTInvalidInput (msg )
1862
1866
1863
1867
# Decide which virtualfile_from_ function to use
1864
1868
_virtualfile_from = {
@@ -2110,7 +2114,8 @@ def read_virtualfile(
2110
2114
if kind is None : # Return the ctypes void pointer
2111
2115
return pointer
2112
2116
if kind == "cube" :
2113
- raise NotImplementedError (f"kind={ kind } is not supported yet." )
2117
+ msg = f"kind={ kind } is not supported yet."
2118
+ raise NotImplementedError (msg )
2114
2119
dtype = {"dataset" : _GMT_DATASET , "grid" : _GMT_GRID , "image" : _GMT_IMAGE }[kind ]
2115
2120
return ctp .cast (pointer , ctp .POINTER (dtype ))
2116
2121
@@ -2378,5 +2383,6 @@ def extract_region(self) -> np.ndarray:
2378
2383
region .ctypes .data_as (ctp .POINTER (ctp .c_double )),
2379
2384
)
2380
2385
if status != 0 :
2381
- raise GMTCLibError ("Failed to extract region from current figure." )
2386
+ msg = "Failed to extract region from current figure."
2387
+ raise GMTCLibError (msg )
2382
2388
return region
0 commit comments