From 87bce92f6cc72bf2e8b05b5ee8940e0e31044456 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:39:55 -0700 Subject: [PATCH 1/7] Set up linkcode Remove theme "show source" button for doc source and unset viewcode extension in lieu of linkcode. Link parser adapted from NumPy, Pandas implementations and forwards to appropriate GitHub ref for source code. --- docs/conf.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 87493d09c4d..fc7d86660af 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,6 +10,7 @@ # serve to show the default. from datetime import datetime +import inspect import os from pathlib import Path import re @@ -37,9 +38,9 @@ 'sphinx.ext.autosummary', 'sphinx.ext.coverage', 'sphinx.ext.intersphinx', + 'sphinx.ext.linkcode', 'sphinx.ext.mathjax', 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', 'sphinx_design', 'sphinx_gallery.gen_gallery', 'matplotlib.sphinxext.plot_directive', @@ -316,7 +317,7 @@ # html_split_index = False # If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True +html_show_sourcelink = False # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. # html_show_sphinx = True @@ -452,3 +453,61 @@ r'https://docs.github.com/': {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; ' 'rv:24.0) Gecko/20100101 Firefox/24.0'} } + +# Function to resolve source code links for `linkcode` +# adapted from NumPy, Pandas implementations +def linkcode_resolve(domain, info): + """ + Determine the URL corresponding to Python object + """ + if domain != "py": + return None + + modname = info["module"] + fullname = info["fullname"] + + submod = sys.modules.get(modname) + if submod is None: + return None + + obj = submod + for part in fullname.split("."): + try: + obj = getattr(obj, part) + except AttributeError: + return None + + try: + fn = inspect.getsourcefile(inspect.unwrap(obj)) + except TypeError: + try: # property + fn = inspect.getsourcefile(inspect.unwrap(obj.fget)) + except (AttributeError, TypeError): + fn = None + if not fn: + return None + + try: + source, lineno = inspect.getsourcelines(obj) + except TypeError: + try: # property + source, lineno = inspect.getsourcelines(obj.fget) + except (AttributeError, TypeError): + lineno = None + except OSError: + lineno = None + + if lineno: + linespec = f"#L{lineno}-L{lineno + len(source) - 1}" + else: + linespec = "" + + fn = os.path.relpath(fn, start=os.path.dirname(metpy.__file__)) + + if "+" in metpy.__version__: + return f"https://github.com/Unidata/MetPy/blob/main/src/metpy/{fn}{linespec}" + else: + return ( + f"https://github.com/Unidata/MetPy/blob/" + f"v{metpy.__version__}/src/metpy/{fn}{linespec}" + ) From eb273676498588ad37ce29044e18fae87449e568 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:41:09 -0700 Subject: [PATCH 2/7] Choose units funcs to doc --- src/metpy/units.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/metpy/units.py b/src/metpy/units.py index 8e1e35b9902..726939b18f7 100644 --- a/src/metpy/units.py +++ b/src/metpy/units.py @@ -25,6 +25,10 @@ import numpy as np import pint +from .package_tools import Exporter + +exporter = Exporter(globals()) + log = logging.getLogger(__name__) UndefinedUnitError = pint.UndefinedUnitError @@ -55,6 +59,7 @@ def _fix_udunits_div(string): _fix_udunits_div] +@exporter.export def setup_registry(reg): """Set up a given registry with MetPy's default tweaks and settings.""" reg.autoconvert_offset_to_baseunit = True @@ -95,6 +100,7 @@ def setup_registry(reg): warnings.simplefilter('ignore', category=pint.UnitStrippedWarning) +@exporter.export def pandas_dataframe_to_unit_arrays(df, column_units=None): """Attach units to data in pandas dataframes and return quantities. From ec509e2d29b21819c1ba8aa44b12ffaa95301fd2 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:42:02 -0700 Subject: [PATCH 3/7] Clean up theme Modify color and nav button specs to fit theme updates. Remove duplicate period. --- docs/_static/theme-unidata.css | 13 +++++++++++-- docs/conf.py | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/_static/theme-unidata.css b/docs/_static/theme-unidata.css index c6f6c796a3a..8e538d7bc2c 100644 --- a/docs/_static/theme-unidata.css +++ b/docs/_static/theme-unidata.css @@ -1,5 +1,5 @@ /* Define "Unidata Blue" RGB values */ -:root { +html { --unidata-blue-rgb: 6, 119, 143; } @@ -19,10 +19,19 @@ .bd-header .navbar-nav>.nav-item>.nav-link, .bd-header .dropdown-toggle, -.bd-header .fa-solid { +.bd-header .fa-solid, +.bd-header .btn { color: #fff !important; } +.version-switcher__button { + border-color: #fff !important; +} + +.search-button { + padding: 0 0 0; +} + .navbar-nav .dropdown-menu { background-color: var(--pst-color-background); } diff --git a/docs/conf.py b/docs/conf.py index fc7d86660af..5cb6148454a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -139,8 +139,8 @@ # noinspection PyShadowingBuiltins copyright = ( - f'2008\u2013{cur_date:%Y}, MetPy Developers.' - 'Development is supported by Unidata and the National Science Foundation.' + f'2008\u2013{cur_date:%Y}, MetPy Developers. ' + 'Development is supported by Unidata and the National Science Foundation' ) # The version info for the project you're documenting, acts as replacement for @@ -214,13 +214,13 @@ { 'name': 'GitHub', 'url': 'https://github.com/Unidata/MetPy', - 'icon': 'fa-brands fa-github-square', + 'icon': 'fa-brands fa-github', 'type': 'fontawesome', }, { 'name': 'Twitter', 'url': 'https://twitter.com/MetPy', - 'icon': 'fa-brands fa-twitter-square', + 'icon': 'fa-brands fa-twitter', 'type': 'fontawesome', } ], From 00b3e48fabfe9a2bb01d67896291353be9cd12ea Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:42:18 -0700 Subject: [PATCH 4/7] Silence pandas warnings --- docs/userguide/index.rst | 4 ++-- examples/plots/surface_declarative.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index 414957080e2..2390b3cfada 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -129,8 +129,8 @@ Bulletin of the American Meteorological Society. from metpy.cbook import get_test_data import metpy.plots as mpplots - data = pd.read_csv(get_test_data('SFC_obs.csv', as_file_obj=False), - infer_datetime_format=True, parse_dates=['valid']) + data = pd.read_csv(get_test_data('SFC_obs.csv', as_file_obj=False)) + data['valid'] = pd.to_datetime(data['valid'], format='%Y-%m-%d %H:%M:%S') obs = mpplots.PlotObs() obs.data = data diff --git a/examples/plots/surface_declarative.py b/examples/plots/surface_declarative.py index 72556fc1b01..89f69be2510 100644 --- a/examples/plots/surface_declarative.py +++ b/examples/plots/surface_declarative.py @@ -27,8 +27,8 @@ # Python script. The data are pre-processed to determine sky cover and weather symbols from # text output. -data = pd.read_csv(get_test_data('SFC_obs.csv', as_file_obj=False), - infer_datetime_format=True, parse_dates=['valid']) +data = pd.read_csv(get_test_data('SFC_obs.csv', as_file_obj=False)) +data['valid'] = pd.to_datetime(data['valid'], format='%Y-%m-%d %H:%M:%S') ######################################## # **Plotting the data** From b015a254f13dd12bb37d43d8b1eb488205d31ad5 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:42:26 -0700 Subject: [PATCH 5/7] Add calendar to docs home --- docs/index.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 0eaa90e2b11..e2be642a592 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -69,6 +69,19 @@ If you're new to MetPy, check out our :doc:`Getting Started ` +of MetPy GitHub Discussions. + +.. raw:: html + + + + Our up-to-date references for grants and funding can be found `here `_. .. image:: _static/NSF.jpg From d48da28cfbfe310272f423c3ed4c615f26eb9b0c Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 14:53:38 -0700 Subject: [PATCH 6/7] Add calendar navbar link --- docs/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 5cb6148454a..1683f016ba6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -222,6 +222,12 @@ 'url': 'https://twitter.com/MetPy', 'icon': 'fa-brands fa-twitter', 'type': 'fontawesome', + }, + { + 'name': 'Calendar', + 'url': 'https://calendar.google.com/calendar/embed?src=c_596cc34cd7196caec223786795c8730786aead6e2dbffe03403186f203075973%40group.calendar.google.com&ctz=America%2FDenver', + 'icon': 'fa-solid fa-calendar', + 'type': 'fontawesome', } ], 'use_edit_page_button': False, From b3fe3104cc269103c66c41a06ae4a7a6b55ccaa2 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 17 Nov 2023 15:05:03 -0700 Subject: [PATCH 7/7] Lint --- docs/index.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index e2be642a592..caa66f25d5a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,6 @@ with weather data. MetPy supports Python >= 3.9 and is freely available under a If you're new to MetPy, check out our :doc:`Getting Started ` guide. - .. grid:: 1 2 2 2 :gutter: 2 @@ -68,21 +67,21 @@ If you're new to MetPy, check out our :doc:`Getting Started ` +Check out the MetPy Community Calendar below. The bi-weekly MetPy Community Dev Call +is an open discussion for community input, developer highlights and updates, and +community code showcase opportunities. Stop by! +Find more information in the pinned thread in the +`Announcements section ` of MetPy GitHub Discussions. .. raw:: html - -Our up-to-date references for grants and funding can be found `here `_. +Our up-to-date references for grants and funding can be found +`here `_. .. image:: _static/NSF.jpg :width: 100 px