Skip to content

Add a package-level variable __gmt_version__ for development use #2362

Closed

Description

@seisman

Description of the desired feature

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:

from packaging.version import Version
from pygmt import clib

def get_gmt_version():
	with clib.Session() as _lib:                                                    
	    return Version(_lib.info["version"])

Are you willing to help implement and maintain this feature?

Yes, but the details need more discussions.

Activity

  1. added
    feature request
    question
    on Feb 12, 2023
  2. seisman commented on Feb 13, 2023

    @seisman
    MemberAuthor

    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"):
        ...
    
  3. maxrjones commented on Feb 13, 2023

    @maxrjones
    Member

    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.

  4. removed
    question
    on Feb 14, 2023
  5. 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
  6. added this to the 0.9.0 milestone on Feb 16, 2023
  7. seisman commented on Feb 16, 2023

    @seisman
    MemberAuthor

    A package-level variable __gmt_version__ will be added in #2366.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions