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

Replace pkg_resources with importlib.metadata #1674

Merged
merged 8 commits into from
Dec 20, 2021
13 changes: 6 additions & 7 deletions pygmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"""

import atexit as _atexit

from pkg_resources import get_distribution
from importlib.metadata import version
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved

# Import modules to make the high-level GMT Python API
from pygmt import datasets
Expand Down Expand Up @@ -63,7 +62,7 @@
)

# Get semantic version through setuptools-scm
__version__ = f'v{get_distribution("pygmt").version}' # e.g. v0.1.2.dev3+g0ab3cd78
__version__ = version("pygmt") # e.g. v0.1.2.dev3+g0ab3cd78
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
__commit__ = __version__.split("+g")[-1] if "+g" in __version__ else "" # 0ab3cd78

# Start our global modern mode session
Expand Down Expand Up @@ -135,10 +134,10 @@ def _get_ghostscript_version():

for gs_cmd in cmds:
try:
version = subprocess.check_output(
gs_version = subprocess.check_output(
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
[gs_cmd, "--version"], universal_newlines=True
).strip()
return version
return gs_version
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
except FileNotFoundError:
continue
return None
Expand All @@ -148,10 +147,10 @@ def _get_gmt_version():
Get GMT version.
"""
try:
version = subprocess.check_output(
gmt_version = subprocess.check_output(
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
["gmt", "--version"], universal_newlines=True
).strip()
return version
return gmt_version
michaelgrund marked this conversation as resolved.
Show resolved Hide resolved
except FileNotFoundError:
return None

Expand Down