GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
763 stars 219 forks source link

Refactor the _get_module_version function using importlib and add two more tests #3538

Closed seisman closed 4 weeks ago

seisman commented 4 weeks ago

The private _get_module_version function was initially added 4 years ago in PR #466. At that time, we supported Python 3.6-3.8 and importlib.metadata was not available yet.

importlib.metadata was added in Python 3.8. With this module, getting package version can be greatly simplified.

This PR simplifies the _get_module_version function and also add two more tests related to Ghostscript to increase code coverage by 0.16% (now we reach 98.49%).

Without optional packages:

PyGMT information:
  version: v0.13.1.dev94+ge7c91571
System information:
  python: 3.10.15 | packaged by conda-forge | (main, Sep 30 2024, 17:51:04) [GCC 13.3.0]
  executable: /home/runner/micromamba/envs/pygmt/bin/python
  machine: Linux-6.5.0-1025-azure-x86_64-with-glibc2.35
Dependency information:
  numpy: 1.24.4
  pandas: 2.0.3
  xarray: 2023.4.2
  netCDF4: 1.7.1
  packaging: 24.1
  contextily: None
  geopandas: None
  IPython: None
  rioxarray: None
  gdal: 3.9.2
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /home/runner/micromamba/envs/pygmt/share/gmt
  plugin dir: /home/runner/micromamba/envs/pygmt/lib/gmt/plugins
  library path: /home/runner/micromamba/envs/pygmt/lib/libgmt.so
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0

With optional packages:

PyGMT information:
  version: v0.13.1.dev94+ge7c91571
System information:
  python: 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0]
  executable: /home/runner/micromamba/envs/pygmt/bin/python
  machine: Linux-6.5.0-1025-azure-x86_64-with-glibc2.35
Dependency information:
  numpy: 2.1.2
  pandas: 2.2.3
  xarray: 2024.9.0
  netCDF4: 1.7.1
  packaging: 24.1
  contextily: 1.6.2
  geopandas: 1.0.1
  IPython: 8.28.0
  rioxarray: 0.17.0
  gdal: 3.9.2
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /home/runner/micromamba/envs/pygmt/share/gmt
  plugin dir: /home/runner/micromamba/envs/pygmt/lib/gmt/plugins
  library path: /home/runner/micromamba/envs/pygmt/lib/libgmt.so
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0