Skip to content

Commit 5a033b3

Browse files
authored
TYP: Add type hints to the check_libgmt function and improve docstrings and tests (#3071)
1 parent 5822b34 commit 5a033b3

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

pygmt/clib/loading.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,29 @@ def clib_full_names(env=None):
150150
yield libname
151151

152152

153-
def check_libgmt(libgmt):
153+
def check_libgmt(libgmt: ctypes.CDLL):
154154
"""
155-
Make sure that libgmt was loaded correctly.
155+
Make sure the GMT shared library was loaded correctly.
156156
157-
Checks if it defines some common required functions.
158-
159-
Does nothing if everything is fine. Raises an exception if any of the
160-
functions are missing.
157+
Checks if the GMT shared library defines a few of the required functions. Does
158+
nothing if everything is fine. Raises an exception if any of the functions are
159+
missing.
161160
162161
Parameters
163162
----------
164-
libgmt : :py:class:`ctypes.CDLL`
163+
libgmt
165164
A shared library loaded using ctypes.
166165
167166
Raises
168167
------
169168
GMTCLibError
170169
"""
171-
# Check if a few of the functions we need are in the library
172-
functions = ["Create_Session", "Get_Enum", "Call_Module", "Destroy_Session"]
173-
for func in functions:
170+
for func in ["Create_Session", "Get_Enum", "Call_Module", "Destroy_Session"]:
174171
if not hasattr(libgmt, "GMT_" + func):
175172
msg = (
176173
f"Error loading '{libgmt._name}'. Couldn't access function GMT_{func}. "
177-
"Ensure that you have installed an up-to-date GMT version 6 library. "
178-
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
179-
"directory of the GMT 6 library."
174+
"Ensure that you have installed an up-to-date GMT version 6 library and "
175+
"set the environment variable 'GMT_LIBRARY_PATH' to the directory of "
176+
"the GMT 6 library."
180177
)
181178
raise GMTCLibError(msg)

pygmt/tests/test_clib_loading.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ def test_check_libgmt():
3535
Make sure check_libgmt fails when given a bogus library.
3636
"""
3737
libgmt = FakedLibGMT("/path/to/libgmt.so")
38-
msg = (
39-
f"Error loading '{libgmt._name}'. "
40-
"Couldn't access function GMT_Create_Session. "
41-
"Ensure that you have installed an up-to-date GMT version 6 library. "
42-
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
43-
"directory of the GMT 6 library."
44-
)
38+
msg = f"Error loading '{libgmt}'. Couldn't access function GMT_Create_Session."
4539
with pytest.raises(GMTCLibError, match=msg):
4640
check_libgmt(libgmt)
4741

0 commit comments

Comments
 (0)