Skip to content

Commit

Permalink
Expose driver base classes via API (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Jul 9, 2024
1 parent 2119d54 commit 7c0a5a7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/sections/user_guide/api/driver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
``uwtools.api.driver``
======================

.. automodule:: uwtools.api.driver
:inherited-members:
:members:
1 change: 1 addition & 0 deletions docs/sections/user_guide/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ API
chgres_cube
config
esg_grid
driver
file
filter_topo
fv3
Expand Down
28 changes: 28 additions & 0 deletions src/uwtools/api/driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
API access to the ``uwtools`` driver base classes.
"""

import importlib
import sys

_CLASSNAMES = [
"Assets",
"AssetsCycleBased",
"AssetsCycleAndLeadtimeBased",
"AssetsTimeInvariant",
"Driver",
"DriverCycleBased",
"DriverCycleAndLeadtimeBased",
"DriverTimeInvariant",
]


def _add_classes():
m = importlib.import_module("uwtools.drivers.driver")
for classname in _CLASSNAMES:
setattr(sys.modules[__name__], classname, getattr(m, classname))
__all__.append(classname)


__all__: list[str] = []
_add_classes()
2 changes: 1 addition & 1 deletion src/uwtools/drivers/ww3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class WaveWatchIII(AssetsCycleBased):
"""
A library driver for ww3.
An assets driver for ww3.
"""

# Workflow tasks
Expand Down
25 changes: 25 additions & 0 deletions src/uwtools/tests/api/test_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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", driver_api._CLASSNAMES)
def test_driver(classname):
assert getattr(driver_api, classname) is getattr(driver_lib, classname)


def test_public_attributes():
# 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):
obj = getattr(driver_api, name)
if name.startswith("_") or ismodule(obj):
continue
assert isclass(obj)
assert name in driver_api._CLASSNAMES

0 comments on commit 7c0a5a7

Please sign in to comment.