From eb5fa5b2d83352466587ea48d72969f0c0e63e2f Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sun, 19 Dec 2021 12:51:42 +0100 Subject: [PATCH 1/5] Replace pkg_resources with importlib.metadata Address #1672 If I understood it correctly this PR should not be merged before we drop Python 3.7 suppoort next week on Dec. 26, 2021. --- pygmt/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index 4a0cc63f786..ebb3ccd1d87 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -20,7 +20,7 @@ import atexit as _atexit -from pkg_resources import get_distribution +from importlib.metadata import version # Import modules to make the high-level GMT Python API from pygmt import datasets @@ -63,7 +63,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 __commit__ = __version__.split("+g")[-1] if "+g" in __version__ else "" # 0ab3cd78 # Start our global modern mode session From e1907b08b7fdbde3206bc47d1df80182e3d99e15 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 19 Dec 2021 12:54:44 +0100 Subject: [PATCH 2/5] format --- pygmt/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index ebb3ccd1d87..08b6aafd633 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -19,7 +19,6 @@ """ import atexit as _atexit - from importlib.metadata import version # Import modules to make the high-level GMT Python API @@ -63,7 +62,7 @@ ) # Get semantic version through setuptools-scm -__version__ = version("pygmt") # e.g. v0.1.2.dev3+g0ab3cd78 +__version__ = version("pygmt") # e.g. v0.1.2.dev3+g0ab3cd78 __commit__ = __version__.split("+g")[-1] if "+g" in __version__ else "" # 0ab3cd78 # Start our global modern mode session From 6e4866c55a9920503669e2cfcae1784f75bf94de Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 20 Dec 2021 13:31:43 +0100 Subject: [PATCH 3/5] rename version variables --- pygmt/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index 08b6aafd633..b99606a856e 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -134,10 +134,10 @@ def _get_ghostscript_version(): for gs_cmd in cmds: try: - version = subprocess.check_output( + gs_version = subprocess.check_output( [gs_cmd, "--version"], universal_newlines=True ).strip() - return version + return gs_version except FileNotFoundError: continue return None @@ -147,10 +147,10 @@ def _get_gmt_version(): Get GMT version. """ try: - version = subprocess.check_output( + gmt_version = subprocess.check_output( ["gmt", "--version"], universal_newlines=True ).strip() - return version + return gmt_version except FileNotFoundError: return None From edaeb3614226f00dd5b00e3e95d2a0e202b3e239 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:00:00 +0100 Subject: [PATCH 4/5] Update pygmt/__init__.py Damn missed that. Thanks @seisman. Co-authored-by: TIAN Dongdong --- pygmt/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index b99606a856e..4e7fb0a60fa 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -62,7 +62,7 @@ ) # Get semantic version through setuptools-scm -__version__ = version("pygmt") # e.g. v0.1.2.dev3+g0ab3cd78 +__version__ = f'v{version("pygmt")}' # e.g. v0.1.2.dev3+g0ab3cd78 __commit__ = __version__.split("+g")[-1] if "+g" in __version__ else "" # 0ab3cd78 # Start our global modern mode session From 52642f64a757c6e346ab821b08365c02928599d1 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:38:55 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: TIAN Dongdong --- pygmt/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pygmt/__init__.py b/pygmt/__init__.py index 4e7fb0a60fa..9f4e7fc6235 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -134,10 +134,9 @@ def _get_ghostscript_version(): for gs_cmd in cmds: try: - gs_version = subprocess.check_output( + return subprocess.check_output( [gs_cmd, "--version"], universal_newlines=True ).strip() - return gs_version except FileNotFoundError: continue return None @@ -147,10 +146,9 @@ def _get_gmt_version(): Get GMT version. """ try: - gmt_version = subprocess.check_output( + return subprocess.check_output( ["gmt", "--version"], universal_newlines=True ).strip() - return gmt_version except FileNotFoundError: return None