From b441efba8011ec3bf88437bd8f54751cc60b4bd2 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 6 Aug 2024 15:58:26 +0800 Subject: [PATCH] doc: Determine the minimum required versions of dependencies from package metadata --- doc/conf.py | 26 ++++++++++++++++---------- doc/install.md | 4 ++-- doc/minversions.md | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 9348960f325..c32d22cd078 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -3,18 +3,25 @@ """ import datetime -from importlib.metadata import metadata +import importlib -# ruff: isort: off -from sphinx_gallery.sorting import ExplicitOrder, ExampleTitleSortKey -from pygmt.clib import required_gmt_version +from packaging.requirements import Requirement from pygmt import __commit__, __version__ +from pygmt.clib import required_gmt_version from pygmt.sphinx_gallery import PyGMTScraper +from sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder -# ruff: isort: on - -requires_python = metadata("pygmt")["Requires-Python"] -requires_gmt = f">={required_gmt_version}" +# Dictionary for dependency name and minimum required version. +requirements = { + Requirement(requirement).name: str(Requirement(requirement).specifier) + for requirement in importlib.metadata.requires("pygmt") +} +requirements.update( + { + "python": importlib.metadata.metadata("pygmt")["Requires-Python"], + "gmt": f">={required_gmt_version}", + } +) extensions = [ "myst_parser", @@ -51,8 +58,7 @@ ] # These enable substitutions using {{ key }} in the Markdown files myst_substitutions = { - "requires_python": requires_python, - "requires_gmt": requires_gmt, + "requires": requirements, } diff --git a/doc/install.md b/doc/install.md index a17d6e237d4..e6869fb8cd2 100644 --- a/doc/install.md +++ b/doc/install.md @@ -59,7 +59,7 @@ development version. ## Which Python? -PyGMT is tested to run on Python {{ requires_python }}. +PyGMT is tested to run on Python {{ requires.python }}. We recommend using the [Miniforge](https://github.com/conda-forge/miniforge#miniforge3) Python distribution to ensure you have all dependencies installed and @@ -69,7 +69,7 @@ your computer and doesn't interfere with any other Python installations on your ## Which GMT? -PyGMT requires Generic Mapping Tools (GMT) {{ requires_gmt }} since there are many +PyGMT requires Generic Mapping Tools (GMT) {{ requires.gmt }} since there are many changes being made to GMT itself in response to the development of PyGMT. Compiled conda packages of GMT for Linux, macOS and Windows are provided through diff --git a/doc/minversions.md b/doc/minversions.md index dc3e0f4c7e7..0a09ae8c4a9 100644 --- a/doc/minversions.md +++ b/doc/minversions.md @@ -12,7 +12,7 @@ after their initial release. | PyGMT Version | GMT | Python | NumPy | Pandas | Xarray | |---|---|---|---|---|---| -| [Dev][]* [[Docs][Docs Dev]] | >=6.3.0 | >=3.10 | >=1.24 | >=1.5 | >=2022.09 | +| [Dev][]* [[Docs][Docs Dev]] | {{ requires.gmt }} | {{ requires.python }} | {{ requires.numpy }} | {{ requires.pandas }} | {{ requires.xarray }} | | [v0.12.0][] [[Docs][Docs v0.12.0]] | >=6.3.0 | >=3.10 | >=1.23 | >=1.5 | >=2022.06 | | [v0.11.0][] [[Docs][Docs v0.11.0]] | >=6.3.0 | >=3.9 | >=1.23 | | | | [v0.10.0][] [[Docs][Docs v0.10.0]] | >=6.3.0 | >=3.9 | >=1.22 | | |