|
23 | 23 | from uwtools.drivers.support import graph
|
24 | 24 | from uwtools.drivers.support import tasks as _tasks
|
25 | 25 | from uwtools.logging import log
|
| 26 | +from uwtools.strings import STR |
26 | 27 | from uwtools.utils.api import ensure_data_source
|
27 | 28 |
|
28 | 29 |
|
@@ -62,22 +63,27 @@ def execute(
|
62 | 63 | """
|
63 | 64 | if not (class_ := _get_driver_class(module, classname)):
|
64 | 65 | return False
|
| 66 | + args = dict(locals()) |
65 | 67 | accepted = set(getfullargspec(class_).args)
|
66 |
| - non_optional = {"cycle", "leadtime"} |
67 |
| - required = accepted & non_optional |
| 68 | + non_optional = {STR.cycle, STR.leadtime} |
| 69 | + for arg in sorted([STR.batch, *non_optional]): |
| 70 | + if args.get(arg) and arg not in accepted: |
| 71 | + log.error("%s does not accept argument '%s'", classname, arg) |
| 72 | + return False |
| 73 | + for arg in sorted(non_optional): |
| 74 | + if arg in accepted and args[arg] is None: |
| 75 | + log.error("%s requires argument '%s'", classname, arg) |
| 76 | + return False |
68 | 77 | kwargs = dict(
|
69 | 78 | config=ensure_data_source(config, bool(stdin_ok)),
|
70 | 79 | dry_run=dry_run,
|
71 | 80 | key_path=key_path,
|
72 | 81 | schema_file=schema_file or Path(module).with_suffix(".jsonschema"),
|
73 | 82 | )
|
74 |
| - for arg in sorted(non_optional): |
75 |
| - if arg in accepted and locals()[arg] is None: |
76 |
| - log.error("%s requires argument '%s'", classname, arg) |
77 |
| - return False |
78 |
| - for arg in sorted(["batch", *required]): |
| 83 | + required = non_optional & accepted |
| 84 | + for arg in sorted([STR.batch, *required]): |
79 | 85 | if arg in accepted:
|
80 |
| - kwargs[arg] = locals()[arg] |
| 86 | + kwargs[arg] = args[arg] |
81 | 87 | driverobj = class_(**kwargs)
|
82 | 88 | log.debug("Instantiated %s with: %s", classname, kwargs)
|
83 | 89 | getattr(driverobj, task)()
|
|
0 commit comments