Skip to content

Commit ef57ac5

Browse files
committed
Add an internal utility function _get_gmt_version
1 parent 454380a commit ef57ac5

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

pygmt/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@
7676
_atexit.register(_end)
7777

7878

79+
def _get_gmt_version():
80+
"""
81+
Return the GMT version string.
82+
83+
Returns
84+
-------
85+
str
86+
The GMT version string.
87+
"""
88+
with Session() as lib:
89+
return lib.info["version"]
90+
91+
7992
def print_clib_info():
8093
"""
8194
Print information about the GMT shared library that we can find.

pygmt/tests/test_accessor.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
import pytest
88
import xarray as xr
99
from packaging.version import Version
10-
from pygmt import clib, which
10+
from pygmt import _get_gmt_version, clib, which
1111
from pygmt.exceptions import GMTInvalidInput
1212

13-
with clib.Session() as _lib:
14-
gmt_version = Version(_lib.info["version"])
15-
1613

1714
def test_accessor_gridline_cartesian():
1815
"""
@@ -76,7 +73,7 @@ def test_accessor_set_non_boolean():
7673

7774

7875
@pytest.mark.skipif(
79-
gmt_version < Version("6.4.0"),
76+
Version(_get_gmt_version()) < Version("6.4.0"),
8077
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/6615",
8178
)
8279
@pytest.mark.xfail(

pygmt/tests/test_grdfill.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
import pytest
88
import xarray as xr
99
from packaging.version import Version
10-
from pygmt import clib, grdfill, load_dataarray
10+
from pygmt import _get_gmt_version, clib, grdfill, load_dataarray
1111
from pygmt.exceptions import GMTInvalidInput
1212
from pygmt.helpers import GMTTempFile
1313
from pygmt.helpers.testing import load_static_earth_relief
1414

15-
with clib.Session() as _lib:
16-
gmt_version = Version(_lib.info["version"])
17-
1815

1916
@pytest.fixture(scope="module", name="grid")
2017
def fixture_grid():
@@ -87,7 +84,7 @@ def test_grdfill_dataarray_out(grid, expected_grid):
8784

8885

8986
@pytest.mark.skipif(
90-
gmt_version < Version("6.4.0"),
87+
Version(_get_gmt_version()) < Version("6.4.0"),
9188
reason="Upstream bug/crash fixed in https://github.com/GenericMappingTools/gmt/pull/6418.",
9289
)
9390
def test_grdfill_asymmetric_pad(grid, expected_grid):

0 commit comments

Comments
 (0)