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

Add output method for base driver class. #615

Closed
5 tasks done
maddenp-noaa opened this issue Oct 22, 2024 · 0 comments · Fixed by #616
Closed
5 tasks done

Add output method for base driver class. #615

maddenp-noaa opened this issue Oct 22, 2024 · 0 comments · Fixed by #616
Assignees

Comments

@maddenp-noaa
Copy link
Collaborator

maddenp-noaa commented Oct 22, 2024

AC

  • Add default instance @property method output() to Driver base class.
  • Define uwtools.exceptions.UWNotImplemented and raise it from the default output().
  • Test default output() via ConcreteDriver* test subclass(es) in test_driver.py.
  • Add unit test to each existing driver test module (test_chgres_cube.py et al.) where the tested driver subclasses Driver. The test should call output() and assert that the expected exception is raised.
  • Update all driver unit tests to include output in the list of methods inherited from the base class.

Description

This method will serve as the default behavior for when a subclass has not yet implemented its own output(). It will report to the user that the method hasn't yet been implemented and will raise a UWNotImplemented exception.

Consider implementing, in addition to the API-callable output() method, something like

@external
def  show_output(self):
    yield self.taskname("output")
    print(json.dumps(self.output, indent=2, sort_keys=True))
    yield asset(None, lambda: True)

that can be called from the CLI to show the output() results on stdout. This could then be called as part of the CLI documentation generation to show example output in the CLI docs. (The doc would should be done in per-driver tickets, not here.) The output might look something like

>>> import json
>>> show = lambda x: print(json.dumps(x, indent=2, sort_keys=True))
>>> show("/path/to/foo")
"/path/to/foo"
>>> show(["/path/to/foo1", "/path/to/foo2"])
[
  "/path/to/foo1",
  "/path/to/foo2"
]
>>> show({"foo": ["/path/to/foo1", "/path/to/foo2"], "bar": ["/path/to/bar1", "/path/to/bar2"]})
{
  "bar": [
    "/path/to/bar1",
    "/path/to/bar2"
  ],
  "foo": [
    "/path/to/foo1",
    "/path/to/foo2"
  ]
}

This way, users could use the CLI to see what the output of their driver invocation will look like, and examples can be programmatically included in our CLI docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant