-
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
Refactor clib to avoid checking GMT version repeatedly and only check once when loading the GMT library #3254
Conversation
d2ef07d
to
90ac95d
Compare
07b06ac
to
b42b758
Compare
833efb4
to
9907af7
Compare
9907af7
to
f55d5d4
Compare
func.restype = ctypes.c_float | ||
major, minor, patch = ctypes.c_uint(0), ctypes.c_uint(0), ctypes.c_uint(0) | ||
func(None, major, minor, patch) | ||
return f"{major.value}.{minor.value}.{patch.value}" |
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.
Thoughts on returning an instance of packaging.version.Version
instead of a str?
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.
but __gmt_version__
should be a string.
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.
Mm ok, could also do str(get_gmt_version())
, but ok to just return a string itself. Just thought it could simplify some of the test code.
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.
Just two tiny suggestions. Having the code spread across clib/__init__.py
, clib/loading.py
and clib/session.py
is a little confusing, but seems to make sense after going through it.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Description of proposed changes
In the
Session.__enter__
method, we check if the GMT library version is equal to or newer than the required version. This special method is called when entering the context manager, i.e.,with Session() as lib
. So it means we're repeatedly checking the GMT version.This PR refactors the clib codes to check the GMT version only once when loading the GMT library.
I expect to see some performance improvements
but the benchmarks say no. So I believe the performance improvement should be very little.https://codspeed.io/GenericMappingTools/pygmt/branches/clib/check-version show an average 2% performance improvement.