You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a package-level variable __gmt_version__ for development use #2362
As we're supporting multiple GMT versions, sometimes we need to check the current GMT version and see if it has a specific bug or provides a new feature.
To check the GMT version, we need to write codes like:
from packaging.version import Version
from pygmt import clib
with clib.Session() as _lib:
gmt_version = Version(_lib.info["version"])
if gmt_version >= Version("6.4.0"):
...
The same code is being used in many places, so it's better to write a function for it. The function will be like this:
After thinking more about it, I think it makes more sense to return the GMT version string, rather than a Version object.
from pygmt import clib
def get_gmt_version():
with clib.Session() as _lib:
return _lib.info["version"]
Then in other scripts, we can use:
from pygmt.somewhere import get_gmt_version
from packaging.version import Version
gmt_version = get_gmt_version()
if Version(gmt_version) >= Version("6.5.0"):
...
A utility function that reduces code redundancy sounds good to me, but I think it should be a private function (e.g., _get_gmt_version()) and users should still use pygmt.show_versions() to report the information rather than introducing another way to accomplish the same purpose.
changed the title [-]Add a utility function which returns the GMT version?[/-][+]Add a package-level variable __gmt_version__ for development use[/+]on Feb 16, 2023
Activity
seisman commentedon Feb 13, 2023
After thinking more about it, I think it makes more sense to return the GMT version string, rather than a
Versionobject.Then in other scripts, we can use:
maxrjones commentedon Feb 13, 2023
A utility function that reduces code redundancy sounds good to me, but I think it should be a private function (e.g.,
_get_gmt_version()) and users should still usepygmt.show_versions()to report the information rather than introducing another way to accomplish the same purpose.[-]Add a utility function which returns the GMT version?[/-][+]Add a package-level variable __gmt_version__ for development use[/+]seisman commentedon Feb 16, 2023
A package-level variable
__gmt_version__will be added in #2366.