-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UW-649 Docs for uw execute tool (#569)
- Loading branch information
1 parent
87fe26f
commit 81fd471
Showing
25 changed files
with
250 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ API | |
cdeps | ||
chgres_cube | ||
config | ||
esg_grid | ||
driver | ||
esg_grid | ||
file | ||
filter_topo | ||
fv3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _drivers: | ||
|
||
Drivers | ||
======= | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
``execute`` | ||
=========== | ||
|
||
The ``uw`` mode for executing external drivers. | ||
|
||
.. literalinclude:: execute/help.cmd | ||
:language: text | ||
:emphasize-lines: 1 | ||
.. literalinclude:: execute/help.out | ||
:language: text | ||
|
||
For the three required arguments: | ||
|
||
* ``--module`` specifies the name of the module providing the driver. The name may be an absolute path (e.g. ``/path/to/driver.py``); a path relative to the current directory (e.g. ``driver.py``, ``../driver.py``, ``sub/dir/driver.py``); or a name appropriate to the Python ``import`` statement (e.g. ``driver``, ``my.package.driver``), provided the directory containing the module is on ``PYTHONPATH`` / ``sys.path``. | ||
* ``--class`` specifies the name of a class in the above module that implements the driver, which should use one of the classes exported by ``uwtools.api.driver`` as its base class. | ||
* ``--task`` specifies the name of a method in the above class that implements a :iotaa-readme:`task<tasks>`, decorated with :iotaa-readme:`@task<task>`, :iotaa-readme:`@tasks<tasks-1>`, or :iotaa-readme:`@external<external>`. | ||
|
||
.. _cli_execute_examples: | ||
|
||
Examples | ||
^^^^^^^^ | ||
|
||
These examples use the following inputs: | ||
|
||
Module ``rand.py`` | ||
|
||
.. literalinclude:: execute/rand.py | ||
:language: python | ||
|
||
Schema ``rand.jsonschema`` | ||
|
||
.. literalinclude:: execute/rand.jsonschema | ||
:language: json | ||
|
||
Config ``rand.yaml`` | ||
|
||
.. literalinclude:: execute/rand.yaml | ||
:language: yaml | ||
|
||
* Execute the external driver: | ||
|
||
.. literalinclude:: execute/execute.cmd | ||
:language: text | ||
:emphasize-lines: 2 | ||
.. literalinclude:: execute/execute.out | ||
:language: text | ||
|
||
* If the external driver does not accept an argument that was provided on the command line, it will exit with error. In this case, ``Rand`` inherits from parent class ``AssetsTimeInvariant``, which does not accept a ``cycle`` argument: | ||
|
||
.. literalinclude:: execute/bad-arg.cmd | ||
:language: text | ||
:emphasize-lines: 1 | ||
.. literalinclude:: execute/bad-arg.out | ||
:language: text | ||
|
||
* If the schema file for a driver resides in the same directory as its Python module and has the same filename prefix, as well as a ``.jsonschema`` suffix (e.g. ``rand.jsonschema`` alongside ``rand.py``) then the ``--schema-file`` argument is not required. However, ``--schema-file`` can be used to point to an alternate schema: | ||
|
||
.. literalinclude:: execute/alt-schema.cmd | ||
:language: text | ||
:emphasize-lines: 2 | ||
.. literalinclude:: execute/alt-schema.out | ||
:language: text | ||
|
||
* Other arguments behave identically to the same-named arguments to built-in ``uwtools`` drivers (see :ref:`drivers`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../Makefile.outputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rm -rf /tmp/rand-alt | ||
uw execute --module rand.py --classname Rand --task randfile --config-file alt.yaml --schema-file alt.schema | ||
echo Random integer is $(cat /tmp/rand-alt/randint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[2024-08-08T23:46:07] INFO 0 UW schema-validation errors found | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Initial state: Not Ready | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Checking requirements | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Requirement(s) ready | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Executing | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Final state: Ready | ||
Random integer is 38 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rand.jsonschema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rand: | ||
hi: 100 | ||
lo: 1 | ||
rundir: /tmp/rand-alt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uw execute --module rand.py --classname Rand --task randfile --config-file rand.yaml --cycle 2024-08-08T12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[2024-08-08T23:46:07] ERROR Rand does not accept argument 'cycle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rm -rf /tmp/rand | ||
uw execute --module rand.py --classname Rand --task randfile --config-file rand.yaml | ||
echo Random integer is $(cat /tmp/rand/randint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[2024-08-08T23:46:07] INFO 0 UW schema-validation errors found | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Initial state: Not Ready | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Checking requirements | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Requirement(s) ready | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Executing | ||
[2024-08-08T23:46:07] INFO rand Random-integer file: Final state: Ready | ||
Random integer is 43 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uw execute --help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
usage: uw execute --module MODULE --classname CLASSNAME --task TASK [-h] | ||
[--version] [--config-file PATH] [--schema-file PATH] | ||
[--cycle CYCLE] [--leadtime LEADTIME] [--batch] [--dry-run] | ||
[--graph-file PATH] [--key-path KEY[.KEY...]] [--quiet] | ||
[--verbose] | ||
|
||
Execute external driver. | ||
|
||
Required arguments: | ||
--module MODULE | ||
Path to driver module or name of module on sys.path | ||
--classname CLASSNAME | ||
Name of driver class | ||
--task TASK | ||
Driver task to execute | ||
|
||
Optional arguments: | ||
-h, --help | ||
Show help and exit | ||
--version | ||
Show version info and exit | ||
--config-file PATH, -c PATH | ||
Path to UW YAML config file (default: read from stdin) | ||
--schema-file PATH | ||
Path to schema file to use for validation | ||
--cycle CYCLE | ||
The cycle in ISO8601 format (e.g. 2024-08-08T18) | ||
--leadtime LEADTIME | ||
The leadtime as hours[:minutes[:seconds]] | ||
--batch | ||
Submit run to batch scheduler | ||
--dry-run | ||
Only log info, making no changes | ||
--graph-file PATH | ||
Path to Graphviz DOT output [experimental] | ||
--key-path KEY[.KEY...] | ||
Dot-separated path of keys leading through the config to the driver's | ||
configuration block | ||
--quiet, -q | ||
Print no logging messages | ||
--verbose, -v | ||
Print all logging messages |
28 changes: 28 additions & 0 deletions
28
docs/sections/user_guide/cli/tools/execute/rand.jsonschema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"properties": { | ||
"rand": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"hi": { | ||
"type": "integer" | ||
}, | ||
"lo": { | ||
"type": "integer" | ||
}, | ||
"rundir": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"lo", | ||
"hi", | ||
"rundir" | ||
], | ||
"type": "object" | ||
}, | ||
"required": [ | ||
"rand" | ||
], | ||
"type": "object" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from random import randint | ||
|
||
from iotaa import asset, task | ||
|
||
from uwtools.api.driver import AssetsTimeInvariant | ||
from uwtools.api.logging import use_uwtools_logger | ||
|
||
use_uwtools_logger() | ||
|
||
|
||
class Rand(AssetsTimeInvariant): | ||
|
||
@task | ||
def randfile(self): | ||
""" | ||
A file containing a random integer. | ||
""" | ||
path = self.rundir / "randint" | ||
yield self.taskname("Random-integer file") | ||
yield asset(path, path.is_file) | ||
yield None | ||
path.parent.mkdir(parents=True) | ||
with open(path, "w", encoding="utf-8") as f: | ||
print(randint(self.config["lo"], self.config["hi"]), file=f) | ||
|
||
@property | ||
def driver_name(self): | ||
return "rand" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rand: | ||
hi: 100 | ||
lo: 1 | ||
rundir: /tmp/rand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ Tools | |
:maxdepth: 1 | ||
|
||
config | ||
execute | ||
file | ||
rocoto | ||
template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.