From cc6c4614eefcbcbe0c0de8a7e7ae547cba15d639 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 2 Nov 2023 21:27:31 +0800 Subject: [PATCH 1/6] Add partial type hints support to load_earth_relief --- pygmt/datasets/earth_relief.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 84f7c36d94e..bd1a6c01aa4 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -4,6 +4,9 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence +from typing import Literal, Union + from pygmt.datasets.load_remote_dataset import _load_remote_dataset from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import kwargs_to_strings @@ -14,9 +17,9 @@ @kwargs_to_strings(region="sequence") def load_earth_relief( resolution="01d", - region=None, - registration=None, - data_source="igpp", + region: Union[str, Sequence, None] = None, + registration: Literal["gridline", "pixel", None] = None, + data_source: Literal["igpp", "gebco", "gebcosi", "synbath"] = "igpp", use_srtm=False, ): r""" @@ -63,18 +66,18 @@ def load_earth_relief( ``"04m"``, ``"03m"``, ``"02m"``, ``"01m"``, ``"30s"``, ``"15s"``, ``"03s"``, or ``"01s"``. - region : str or list + region The subregion of the grid to load, in the form of a list [*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. Required for Earth relief grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). - registration : str + registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``"gridline"`` for all resolutions except ``"15s"`` which is ``"pixel"`` only. - data_source : str + data_source Select the source for the Earth relief data. Available options are: - ``"igpp"``: IGPP Earth Relief [Default option]. See From 5c5864c69d52f1578f97e4a61781acfa6f75969d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 15 Nov 2023 17:57:37 +0800 Subject: [PATCH 2/6] Set autodoc_typehints to description --- doc/conf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index 7cc843b1dcc..bb7114e7ccc 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -36,6 +36,9 @@ # Autosummary pages will be generated by sphinx-autogen instead of sphinx-build autosummary_generate = [] +# Autodoc +autodoc_typehints = "description" + # Auto-generate header anchors with MyST parser myst_heading_anchors = 4 # Allow code fences using colons From 9ceacb9c66a602639e4e3d395ec4a851be5a88e2 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 15 Nov 2023 21:25:41 +0800 Subject: [PATCH 3/6] Use the sphinx-autodoc-typehints extension --- .github/workflows/ci_docs.yml | 1 + ci/requirements/docs.yml | 1 + doc/conf.py | 1 + environment.yml | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index f723fddce4a..8adb71356e2 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -93,6 +93,7 @@ jobs: myst-parser panel sphinx + sphinx-autodoc-typehints sphinx-copybutton sphinx-design sphinx-gallery diff --git a/ci/requirements/docs.yml b/ci/requirements/docs.yml index da384363261..138f6589e31 100644 --- a/ci/requirements/docs.yml +++ b/ci/requirements/docs.yml @@ -24,6 +24,7 @@ dependencies: - myst-parser - panel - sphinx + - sphinx-autodoc-typehints - sphinx-copybutton - sphinx-design - sphinx-gallery diff --git a/doc/conf.py b/doc/conf.py index bb7114e7ccc..14bb38dd2ce 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -28,6 +28,7 @@ "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", + "sphinx_autodoc_typehints", "sphinx_copybutton", "sphinx_design", "sphinx_gallery.gen_gallery", diff --git a/environment.yml b/environment.yml index 73b45304436..a455123e0f8 100644 --- a/environment.yml +++ b/environment.yml @@ -37,7 +37,8 @@ dependencies: # Dev dependencies (building documentation) - myst-parser - panel - - sphinx + - sphinx>=3.0 + - sphinx-autodoc-typehints - sphinx-copybutton - sphinx-design - sphinx-gallery From c7be7b10ce27b72d528482a783d44bd85b42b228 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 15 Nov 2023 22:33:12 +0800 Subject: [PATCH 4/6] Remove autodoc_typehints and set typehints_defaults to 'comma' --- doc/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 14bb38dd2ce..c8c33756eec 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -37,9 +37,6 @@ # Autosummary pages will be generated by sphinx-autogen instead of sphinx-build autosummary_generate = [] -# Autodoc -autodoc_typehints = "description" - # Auto-generate header anchors with MyST parser myst_heading_anchors = 4 # Allow code fences using colons @@ -50,6 +47,9 @@ napoleon_use_rtype = False napoleon_use_ivar = True +# sphinx_auto_typehints +typehints_defaults = "comma" + # configure links to GMT docs extlinks = { "gmt-docs": ("https://docs.generic-mapping-tools.org/6.4/%s", None), From 7a3189aebecf2ac4a6f1b1c02d0e683bb213a07e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 4 Dec 2023 23:52:55 +0800 Subject: [PATCH 5/6] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index ba2ef785a2a..60f3319d543 100644 --- a/environment.yml +++ b/environment.yml @@ -36,7 +36,7 @@ dependencies: # Dev dependencies (building documentation) - myst-parser - panel - - sphinx>=3.0 + - sphinx - sphinx-autodoc-typehints - sphinx-copybutton - sphinx-design From f3c1b19ec499d037997d6886acf6b492e7f23923 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 6 Dec 2023 15:33:03 +0800 Subject: [PATCH 6/6] Revert "Add partial type hints support to load_earth_relief" This reverts commit cc6c4614eefcbcbe0c0de8a7e7ae547cba15d639. --- pygmt/datasets/earth_relief.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 97441984e29..62b6bf8cb47 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -4,9 +4,6 @@ The grids are available in various resolutions. """ -from collections.abc import Sequence -from typing import Literal, Union - from pygmt.datasets.load_remote_dataset import _load_remote_dataset from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import kwargs_to_strings @@ -17,9 +14,9 @@ @kwargs_to_strings(region="sequence") def load_earth_relief( resolution="01d", - region: Union[str, Sequence, None] = None, - registration: Literal["gridline", "pixel", None] = None, - data_source: Literal["igpp", "gebco", "gebcosi", "synbath"] = "igpp", + region=None, + registration=None, + data_source="igpp", use_srtm=False, ): r""" @@ -66,18 +63,18 @@ def load_earth_relief( ``"04m"``, ``"03m"``, ``"02m"``, ``"01m"``, ``"30s"``, ``"15s"``, ``"03s"``, or ``"01s"``. - region + region : str or list The subregion of the grid to load, in the form of a list [*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. Required for Earth relief grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). - registration + registration : str Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``"gridline"`` for all resolutions except ``"15s"`` which is ``"pixel"`` only. - data_source + data_source : str Select the source for the Earth relief data. Available options are: - ``"igpp"``: IGPP Earth Relief [Default option]. See