-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues in loading GMT's shared library #977
Conversation
e765e57
to
67244e8
Compare
1. Need to catch `GMTCLibError` error from calling `check_libgmt()` 2. Add a new parameter `lib_fullnames` (default to `clib_full_names()`) to `load_libgmt()` so that we can test more cases 3. Skip a library path if it's known to fail in previous tries 4. Improve the error message, because each library path may fail due to different reasons. 5. Add more tests
67244e8
to
fb28c1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a few comments. After trying to have a go at refactoring the big 'test_load_libgmt_with_broken_libraries', I can see why you've coded it up this way, but it's not easy to follow the code and I worry about the poor maintainer in the future having to understand what is happening 😢
In a way, I wonder if we're overcomplicating the load_libgmt
et al. functions in pygmt/clib/loading.py
. It seems like a crazy amount of possible combinations we're testing (3 OSes, different GMT_LIBRARY_PATHs, libraries that may or may not load, etc). Probably need to have a hard think about whether we can actually simplify the whole loading logic.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
pygmt/clib/loading.py
Outdated
elif os_name.startswith("freebsd"): # FreeBSD | ||
libnames = ["libgmt.so"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change L78:L79 to read:
if os_name.startswith(("linux", "freebsd")):
libnames = ["libgmt.so"]
Just gets rid of one elif statement.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the comprehensive tests @seisman, sorry for dragging this out for so long. Will be good to merge once all the tests pass and the Style Checks errors are resolved.
@weiji14 Thanks for your review. Now the Style Checks reports errors like:
The argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the Style Checks reports errors like:
pygmt/tests/test_clib_loading.py:135:40: W0613: Unused argument 'mock_ctypes' (unused-argument)
The argument
mock_ctypes
is necessary, so I can't remove it. Should I just disable the pylint warning?
Yes.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
- Catch the GMTCLibError error from calling check_libgmt() - Skip a library path if it's known to fail in previous tries - Improve the error message, by combine error message of all tries - Add a new parameter lib_fullnames (default to clib_full_names()) to for easier testing - Add more tests Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Description of proposed changes
The
load_libgmt()
function still has some bugs:pygmt/pygmt/clib/loading.py
Lines 36 to 52 in 6a6171e
OSError
exception, butcheck_libgmt()
may raiseGMTCLibError
exception. So if the library paths are["/path/to/GMT5/libgmt.so", "/path/to/GMT6/libgmt.so", "libgmt.so"]
, theload_libgmt()
function won't be able to the working library.clib_full_names()
function returns a list of all possible paths. Some paths may be duplicated. So, if the paths are["invalid_path_A", "invalid_path_A", "invalid_path_B"]
, we will checkinvalid_path_A
twice.error
only contains the error message of the last library path, but, each library path may fail due to different reasons.This PR makes the following changes:
GMTCLibError
error from callingcheck_libgmt()
(Fixes point 1)lib_fullnames
(default toclib_full_names()
) to for easier testingFixes #
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version