Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose driver base classes via API #523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
maddenp-noaa marked this conversation as resolved.
Show resolved Hide resolved


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()
maddenp-noaa marked this conversation as resolved.
Show resolved Hide resolved
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.
maddenp-noaa marked this conversation as resolved.
Show resolved Hide resolved
"""

# 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
Loading