From 74eedca22e50bc24669f79c20156eaabed5c1ef7 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 3 Jul 2024 15:49:08 +0000 Subject: [PATCH 1/5] WIP --- docs/sections/user_guide/api/driver.rst | 6 ++++++ docs/sections/user_guide/api/index.rst | 1 + src/uwtools/api/driver.py | 17 +++++++++++++++++ src/uwtools/drivers/ww3.py | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 docs/sections/user_guide/api/driver.rst create mode 100644 src/uwtools/api/driver.py diff --git a/docs/sections/user_guide/api/driver.rst b/docs/sections/user_guide/api/driver.rst new file mode 100644 index 000000000..46f0709ce --- /dev/null +++ b/docs/sections/user_guide/api/driver.rst @@ -0,0 +1,6 @@ +``uwtools.api.driver`` +====================== + +.. automodule:: uwtools.api.driver + :inherited-members: + :members: diff --git a/docs/sections/user_guide/api/index.rst b/docs/sections/user_guide/api/index.rst index 62669c885..412153c03 100644 --- a/docs/sections/user_guide/api/index.rst +++ b/docs/sections/user_guide/api/index.rst @@ -5,6 +5,7 @@ API chgres_cube config esg_grid + driver file filter_topo fv3 diff --git a/src/uwtools/api/driver.py b/src/uwtools/api/driver.py new file mode 100644 index 000000000..644a9aa6b --- /dev/null +++ b/src/uwtools/api/driver.py @@ -0,0 +1,17 @@ +""" +API access to the ``uwtools`` driver base classes. +""" + +import sys +from importlib import import_module + + +def _add_classes(): + m = import_module("uwtools.drivers.driver") + for classname in ["Assets"]: + setattr(sys.modules[__name__], classname, getattr(m, classname)) + __all__.append(classname) + + +__all__: list[str] = [] +_add_classes() diff --git a/src/uwtools/drivers/ww3.py b/src/uwtools/drivers/ww3.py index 4414d5685..1d951196f 100644 --- a/src/uwtools/drivers/ww3.py +++ b/src/uwtools/drivers/ww3.py @@ -16,7 +16,7 @@ class WaveWatchIII(Assets): """ - A library driver for ww3. + An assets driver for ww3. """ def __init__( From 422f81da050b20a428bf728e7894dad2a3a1017f Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 3 Jul 2024 16:16:03 +0000 Subject: [PATCH 2/5] Add tests --- src/uwtools/api/driver.py | 8 +++++--- src/uwtools/tests/api/test_driver.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/uwtools/tests/api/test_driver.py diff --git a/src/uwtools/api/driver.py b/src/uwtools/api/driver.py index 644a9aa6b..0f57a2a97 100644 --- a/src/uwtools/api/driver.py +++ b/src/uwtools/api/driver.py @@ -2,13 +2,15 @@ API access to the ``uwtools`` driver base classes. """ +import importlib import sys -from importlib import import_module + +_CLASSNAMES = ["Assets"] def _add_classes(): - m = import_module("uwtools.drivers.driver") - for classname in ["Assets"]: + m = importlib.import_module("uwtools.drivers.driver") + for classname in _CLASSNAMES: setattr(sys.modules[__name__], classname, getattr(m, classname)) __all__.append(classname) diff --git a/src/uwtools/tests/api/test_driver.py b/src/uwtools/tests/api/test_driver.py new file mode 100644 index 000000000..f6b3b30de --- /dev/null +++ b/src/uwtools/tests/api/test_driver.py @@ -0,0 +1,22 @@ +# pylint: disable=missing-function-docstring,protected-access + +from inspect import isclass, ismodule + +from pytest import mark + +from uwtools.api import driver as driver_api +from uwtools.drivers import driver as driver_lib + + +@mark.parametrize("classname", ["Assets"]) +def test_driver(classname): + assert getattr(driver_api, classname) is getattr(driver_lib, classname) + + +def test_no_extras(): + for x in dir(driver_api): + if not x.startswith("_"): + obj = getattr(driver_api, x) + if not ismodule(obj): + assert isclass(obj) + assert x in driver_api._CLASSNAMES From 0d2b782dc30a5256815636627b9589177a475666 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 3 Jul 2024 16:47:31 +0000 Subject: [PATCH 3/5] Update test --- src/uwtools/tests/api/test_driver.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/uwtools/tests/api/test_driver.py b/src/uwtools/tests/api/test_driver.py index f6b3b30de..f75cd4727 100644 --- a/src/uwtools/tests/api/test_driver.py +++ b/src/uwtools/tests/api/test_driver.py @@ -13,10 +13,13 @@ def test_driver(classname): assert getattr(driver_api, classname) is getattr(driver_lib, classname) -def test_no_extras(): - for x in dir(driver_api): - if not x.startswith("_"): - obj = getattr(driver_api, x) - if not ismodule(obj): - assert isclass(obj) - assert x in driver_api._CLASSNAMES +def test_public_attributes(): + # Check that the module is not accidentally exposing unexpected public atttributes. Ignore + # private attributes and imported modules and assert that what remains is an intentionally + # exposed (driver) class. + for name in dir(driver_api): + obj = getattr(driver_api, name) + if name.startswith("_") or ismodule(obj): + continue + assert isclass(obj) + assert name in driver_api._CLASSNAMES From 69e089cde9ecaa9ebed69d86964aa46532f6bab5 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Tue, 9 Jul 2024 14:33:56 +0000 Subject: [PATCH 4/5] Include new driver classes in API --- src/uwtools/api/driver.py | 11 ++++++++++- src/uwtools/tests/api/test_driver.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uwtools/api/driver.py b/src/uwtools/api/driver.py index 0f57a2a97..f724ebc7e 100644 --- a/src/uwtools/api/driver.py +++ b/src/uwtools/api/driver.py @@ -5,7 +5,16 @@ import importlib import sys -_CLASSNAMES = ["Assets"] +_CLASSNAMES = [ + "Assets", + "AssetsCycleBased", + "AssetsCycleAndLeadtimeBased", + "AssetsTimeInvariant", + "Driver", + "DriverCycleBased", + "DriverCycleAndLeadtimeBased", + "DriverTimeInvariant", +] def _add_classes(): diff --git a/src/uwtools/tests/api/test_driver.py b/src/uwtools/tests/api/test_driver.py index f75cd4727..4a0cbe26b 100644 --- a/src/uwtools/tests/api/test_driver.py +++ b/src/uwtools/tests/api/test_driver.py @@ -8,7 +8,7 @@ from uwtools.drivers import driver as driver_lib -@mark.parametrize("classname", ["Assets"]) +@mark.parametrize("classname", driver_api._CLASSNAMES) def test_driver(classname): assert getattr(driver_api, classname) is getattr(driver_lib, classname) From f809d29ba04a118374c0016f0c923985c680b715 Mon Sep 17 00:00:00 2001 From: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com> Date: Tue, 9 Jul 2024 08:55:36 -0600 Subject: [PATCH 5/5] Update src/uwtools/tests/api/test_driver.py Co-authored-by: Emily Carpenter <137525341+elcarpenterNOAA@users.noreply.github.com> --- src/uwtools/tests/api/test_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uwtools/tests/api/test_driver.py b/src/uwtools/tests/api/test_driver.py index 4a0cbe26b..9b1115451 100644 --- a/src/uwtools/tests/api/test_driver.py +++ b/src/uwtools/tests/api/test_driver.py @@ -14,7 +14,7 @@ def test_driver(classname): def test_public_attributes(): - # Check that the module is not accidentally exposing unexpected public atttributes. Ignore + # Check that the module is not accidentally exposing unexpected public attributes. Ignore # private attributes and imported modules and assert that what remains is an intentionally # exposed (driver) class. for name in dir(driver_api):