Skip to content
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

Merged
merged 6 commits into from
Feb 17, 2023

Conversation

seisman
Copy link
Member

@seisman seisman commented Feb 14, 2023

Description of proposed changes

Fixes #2362

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@seisman seisman added the maintenance Boring but important stuff for the core devs label Feb 14, 2023
@seisman seisman added this to the 0.9.0 milestone Feb 14, 2023
@@ -76,6 +76,21 @@
_atexit.register(_end)


def _get_gmt_version():
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@seisman seisman changed the title Add an internal utility function _get_gmt_version Add a package-level variable __gmt_version__ for development use Feb 15, 2023
@seisman seisman marked this pull request as ready for review February 15, 2023 02:01
@seisman seisman marked this pull request as draft February 15, 2023 02:52
Comment on lines +24 to +30
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"]
Copy link
Member Author

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).

@seisman seisman marked this pull request as ready for review February 15, 2023 03:09
@seisman seisman added the needs review This PR has higher priority and needs review. label Feb 15, 2023
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Feb 15, 2023
@seisman seisman requested a review from weiji14 February 16, 2023 15:17
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Feb 17, 2023
@seisman seisman merged commit 2b7acaf into main Feb 17, 2023
@seisman seisman deleted the get_gmt_version branch February 17, 2023 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a package-level variable __gmt_version__ for development use
3 participants