-
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
Add a package-level variable __gmt_version__ for development use #2366
Conversation
ef57ac5
to
727376f
Compare
pygmt/__init__.py
Outdated
@@ -76,6 +76,21 @@ | |||
_atexit.register(_end) | |||
|
|||
|
|||
def _get_gmt_version(): |
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.
I've added a utility function _get_gmt_version
in the pygmt/__init__.py
file. I wonder if it's better to define a package-level variable __gmt_version__
instead.
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.
Sounds good. This would be similar to __gdal_version__
in rasterio
, see https://github.com/rasterio/rasterio/blob/6bf045cc5e02c9f28e78d48b97b308490207d27d/rasterio/__init__.py#L84-L86
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.
Sounds good!
from pygmt import clib | ||
|
||
# Get semantic version through setuptools-scm | ||
__version__ = f'v{version("pygmt")}' # e.g. v0.1.2.dev3+g0ab3cd78 | ||
__commit__ = __version__.split("+g")[-1] if "+g" in __version__ else "" # 0ab3cd78 | ||
with clib.Session() as lib: | ||
__gmt_version__ = lib.info["version"] |
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.
The package-level variable __gmt_version__
is defined here.
I have to put the definition of __gmt_version__
at the top otherwise there will be circular import errors (see https://github.com/GenericMappingTools/pygmt/actions/runs/4179854302/jobs/7240260379).
Description of proposed changes
Fixes #2362
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