Skip to content

Commit

Permalink
omnibus-2024-06-24 (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Jun 25, 2024
1 parent d0439b9 commit 05b9957
Show file tree
Hide file tree
Showing 67 changed files with 359 additions and 322 deletions.
4 changes: 2 additions & 2 deletions src/uwtools/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from pathlib import Path
from typing import List, Optional, Union
from typing import Optional, Union

from uwtools.config.formats.fieldtable import FieldTableConfig as _FieldTableConfig
from uwtools.config.formats.ini import INIConfig as _INIConfig
Expand Down Expand Up @@ -119,7 +119,7 @@ def realize(
update_format: Optional[str] = None,
output_file: Optional[Union[Path, str]] = None,
output_format: Optional[str] = None,
key_path: Optional[List[Union[str, int]]] = None,
key_path: Optional[list[Union[str, int]]] = None,
values_needed: bool = False,
total: bool = False,
dry_run: bool = False,
Expand Down
6 changes: 3 additions & 3 deletions src/uwtools/api/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import datetime as dt
from pathlib import Path
from typing import List, Optional, Union
from typing import Optional, Union

from uwtools.file import FileCopier as _FileCopier
from uwtools.file import FileLinker as _FileLinker
Expand All @@ -16,7 +16,7 @@ def copy(
config: Optional[Union[dict, Path, str]] = None,
cycle: Optional[dt.datetime] = None,
leadtime: Optional[dt.timedelta] = None,
keys: Optional[List[str]] = None,
keys: Optional[list[str]] = None,
dry_run: bool = False,
stdin_ok: bool = False,
) -> bool:
Expand Down Expand Up @@ -48,7 +48,7 @@ def link(
config: Optional[Union[dict, Path, str]] = None,
cycle: Optional[dt.datetime] = None,
leadtime: Optional[dt.timedelta] = None,
keys: Optional[List[str]] = None,
keys: Optional[list[str]] = None,
dry_run: bool = False,
stdin_ok: bool = False,
) -> bool:
Expand Down
10 changes: 5 additions & 5 deletions src/uwtools/api/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from pathlib import Path
from typing import Dict, List, Optional, Union
from typing import Optional, Union

from uwtools.config.atparse_to_jinja2 import convert as _convert_atparse_to_jinja2
from uwtools.config.jinja2 import render as _render
Expand All @@ -18,9 +18,9 @@ def render(
values_format: Optional[str] = None,
input_file: Optional[Union[Path, str]] = None,
output_file: Optional[Union[Path, str]] = None,
overrides: Optional[Dict[str, str]] = None,
overrides: Optional[dict[str, str]] = None,
env: bool = False,
searchpath: Optional[List[str]] = None,
searchpath: Optional[list[str]] = None,
values_needed: bool = False,
dry_run: bool = False,
stdin_ok: bool = False,
Expand Down Expand Up @@ -69,9 +69,9 @@ def render_to_str( # pylint: disable=unused-argument
values_src: Optional[Union[dict, Path, str]] = None,
values_format: Optional[str] = None,
input_file: Optional[Union[Path, str]] = None,
overrides: Optional[Dict[str, str]] = None,
overrides: Optional[dict[str, str]] = None,
env: bool = False,
searchpath: Optional[List[str]] = None,
searchpath: Optional[list[str]] = None,
values_needed: bool = False,
dry_run: bool = False,
) -> str:
Expand Down
28 changes: 14 additions & 14 deletions src/uwtools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from functools import partial
from importlib import import_module
from pathlib import Path
from typing import Any, Callable, Dict, List, NoReturn, Optional, Tuple
from typing import Any, Callable, NoReturn, Optional

import uwtools.api
import uwtools.api.config
Expand All @@ -31,10 +31,10 @@
LEADTIME_DESC = "hours[:minutes[:seconds]]"
TITLE_REQ_ARG = "Required arguments"

Args = Dict[str, Any]
ActionChecks = List[Callable[[Args], Args]]
ModeChecks = Dict[str, ActionChecks]
Checks = Dict[str, ModeChecks]
Args = dict[str, Any]
ActionChecks = list[Callable[[Args], Args]]
ModeChecks = dict[str, ActionChecks]
Checks = dict[str, ModeChecks]


def main() -> None:
Expand All @@ -56,13 +56,13 @@ def main() -> None:
_abort(str(e))
try:
log.debug("Command: %s %s", Path(sys.argv[0]).name, " ".join(sys.argv[1:]))
tools: Dict[str, Callable[..., bool]] = {
tools: dict[str, Callable[..., bool]] = {
STR.config: _dispatch_config,
STR.file: _dispatch_file,
STR.rocoto: _dispatch_rocoto,
STR.template: _dispatch_template,
}
drivers: Dict[str, Callable[..., bool]] = {
drivers: dict[str, Callable[..., bool]] = {
x: partial(_dispatch_to_driver, x)
for x in [
STR.chgrescube,
Expand Down Expand Up @@ -591,7 +591,7 @@ def _add_arg_env(group: Group) -> None:


def _add_arg_file_format(
group: Group, switch: str, helpmsg: str, choices: List[str], required: bool = False
group: Group, switch: str, helpmsg: str, choices: list[str], required: bool = False
) -> None:
group.add_argument(
switch,
Expand Down Expand Up @@ -632,7 +632,7 @@ def _add_arg_input_file(group: Group, required: bool = False) -> None:
)


def _add_arg_input_format(group: Group, choices: List[str], required: bool = False) -> None:
def _add_arg_input_format(group: Group, choices: list[str], required: bool = False) -> None:
group.add_argument(
_switch(STR.infmt),
choices=choices,
Expand Down Expand Up @@ -690,7 +690,7 @@ def _add_arg_output_file(group: Group, required: bool = False) -> None:
)


def _add_arg_output_format(group: Group, choices: List[str], required: bool = False) -> None:
def _add_arg_output_format(group: Group, choices: list[str], required: bool = False) -> None:
group.add_argument(
_switch(STR.outfmt),
choices=choices,
Expand Down Expand Up @@ -758,7 +758,7 @@ def _add_arg_update_file(group: Group, required: bool = False) -> None:
)


def _add_arg_update_format(group: Group, choices: List[str], required: bool = False) -> None:
def _add_arg_update_format(group: Group, choices: list[str], required: bool = False) -> None:
group.add_argument(
_switch(STR.updatefmt),
choices=choices,
Expand All @@ -778,7 +778,7 @@ def _add_arg_values_file(group: Group, required: bool = False) -> None:
)


def _add_arg_values_format(group: Group, choices: List[str]) -> None:
def _add_arg_values_format(group: Group, choices: list[str]) -> None:
group.add_argument(
_switch(STR.valsfmt),
choices=choices,
Expand Down Expand Up @@ -970,7 +970,7 @@ def _check_verbosity(args: Args) -> Args:
return args


def _dict_from_key_eq_val_strings(config_items: List[str]) -> Dict[str, str]:
def _dict_from_key_eq_val_strings(config_items: list[str]) -> dict[str, str]:
"""
Given a list of key=value strings, return a dictionary of key/value pairs.
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def _formatter(prog: str) -> HelpFormatter:
return HelpFormatter(prog, max_help_position=6)


def _parse_args(raw_args: List[str]) -> Tuple[Args, Checks]:
def _parse_args(raw_args: list[str]) -> tuple[Args, Checks]:
"""
Parse command-line arguments.
Expand Down
10 changes: 5 additions & 5 deletions src/uwtools/config/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from copy import deepcopy
from io import StringIO
from pathlib import Path
from typing import List, Optional, Tuple, Union
from typing import Optional, Union

import yaml

Expand Down Expand Up @@ -63,7 +63,7 @@ def _load(self, config_file: Optional[Path]) -> dict:
:param config_file: Path to config file to load.
"""

def _load_paths(self, config_files: List[Path]) -> dict:
def _load_paths(self, config_files: list[Path]) -> dict:
"""
Merge and return the contents of a collection of config files.
Expand All @@ -83,16 +83,16 @@ def _load_paths(self, config_files: List[Path]) -> dict:

# Public methods

def characterize_values(self, values: dict, parent: str) -> Tuple[list, list]:
def characterize_values(self, values: dict, parent: str) -> tuple[list, list]:
"""
Characterize values as complete or as template placeholders.
:param values: The dictionary to examine.
:param parent: Parent key.
:return: Lists of of complete and template-placeholder values.
"""
complete: List[str] = []
template: List[str] = []
complete: list[str] = []
template: list[str] = []
for key, val in values.items():
if isinstance(val, dict):
complete.append(f"{INDENT}{parent}{key}")
Expand Down
20 changes: 10 additions & 10 deletions src/uwtools/config/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from functools import cached_property
from pathlib import Path
from typing import Dict, List, Optional, Set, Union
from typing import Optional, Union

from jinja2 import Environment, FileSystemLoader, StrictUndefined, Undefined, meta
from jinja2.exceptions import UndefinedError
Expand All @@ -26,7 +26,7 @@ def __init__(
self,
values: dict,
template_source: Optional[Union[str, Path]] = None,
searchpath: Optional[List[str]] = None,
searchpath: Optional[list[str]] = None,
) -> None:
"""
:param values: Values needed to render the provided template.
Expand Down Expand Up @@ -88,7 +88,7 @@ def render(self) -> str:
return self._template.render(self._values)

@property
def undeclared_variables(self) -> Set[str]:
def undeclared_variables(self) -> set[str]:
"""
Returns the names of variables needed to render the template.
Expand All @@ -102,7 +102,7 @@ def undeclared_variables(self) -> Set[str]:


def dereference(
val: _ConfigVal, context: dict, local: Optional[dict] = None, keys: Optional[List[str]] = None
val: _ConfigVal, context: dict, local: Optional[dict] = None, keys: Optional[list[str]] = None
) -> _ConfigVal:
"""
Render Jinja2 syntax, wherever possible.
Expand Down Expand Up @@ -152,9 +152,9 @@ def render(
values_format: Optional[str] = None,
input_file: Optional[Path] = None,
output_file: Optional[Path] = None,
overrides: Optional[Dict[str, str]] = None,
overrides: Optional[dict[str, str]] = None,
env: bool = False,
searchpath: Optional[List[str]] = None,
searchpath: Optional[list[str]] = None,
values_needed: bool = False,
dry_run: bool = False,
) -> Optional[str]:
Expand Down Expand Up @@ -286,7 +286,7 @@ def _dry_run_template(rendered_template: str) -> str:
return rendered_template


def _log_missing_values(missing: List[str]) -> None:
def _log_missing_values(missing: list[str]) -> None:
"""
Log values missing from template and raise an exception.
Expand All @@ -305,7 +305,7 @@ def _register_filters(env: Environment) -> Environment:
:return: The input Environment, with filters added.
"""

def path_join(path_components: List[str]) -> str:
def path_join(path_components: list[str]) -> str:
if any(isinstance(x, Undefined) for x in path_components):
raise UndefinedError()
return os.path.join(*path_components)
Expand All @@ -332,7 +332,7 @@ def _report(args: dict) -> None:
def _supplement_values(
values_src: Optional[Union[dict, Path]] = None,
values_format: Optional[str] = None,
overrides: Optional[Dict[str, str]] = None,
overrides: Optional[dict[str, str]] = None,
env: bool = False,
) -> dict:
"""
Expand Down Expand Up @@ -361,7 +361,7 @@ def _supplement_values(
return values


def _values_needed(undeclared_variables: Set[str]) -> None:
def _values_needed(undeclared_variables: set[str]) -> None:
"""
Log variables needed to render the template.
Expand Down
6 changes: 3 additions & 3 deletions src/uwtools/config/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections import OrderedDict
from importlib import import_module
from typing import Dict, Type, Union
from typing import Type, Union

import yaml

Expand Down Expand Up @@ -46,7 +46,7 @@ def format_to_config(fmt: str) -> Type:
return cfgclass


def from_od(d: Union[OrderedDict, Dict]) -> dict:
def from_od(d: Union[OrderedDict, dict]) -> dict:
"""
Returns a (nested) dict with content equivalent to the given (nested) OrderedDict.
Expand Down Expand Up @@ -105,7 +105,7 @@ def convert(self) -> Union[float, int]:
Will raise an exception if the value cannot be represented as the specified type.
"""
converters: Dict[str, Union[Type[float], Type[int]]] = dict(zip(self.TAGS, [float, int]))
converters: dict[str, Union[Type[float], Type[int]]] = dict(zip(self.TAGS, [float, int]))
return converters[self.tag](self.value)


Expand Down
12 changes: 6 additions & 6 deletions src/uwtools/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from pathlib import Path
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, Optional, Union

from uwtools.config.formats.base import Config
from uwtools.config.jinja2 import unrendered
Expand Down Expand Up @@ -82,7 +82,7 @@ def realize_config(
update_format: Optional[str] = None,
output_file: Optional[Path] = None,
output_format: Optional[str] = None,
key_path: Optional[List[Union[str, int]]] = None,
key_path: Optional[list[Union[str, int]]] = None,
values_needed: bool = False,
total: bool = False,
dry_run: bool = False,
Expand Down Expand Up @@ -135,7 +135,7 @@ def _ensure_format(
return fmt


def _print_config_section(config: dict, key_path: List[str]) -> None:
def _print_config_section(config: dict, key_path: list[str]) -> None:
"""
Descends into the config via the given keys, then prints the contents of the located subtree as
key=value pairs, one per line.
Expand All @@ -162,7 +162,7 @@ def _print_config_section(config: dict, key_path: List[str]) -> None:

def _realize_config_input_setup(
input_config: Union[Config, Optional[Path]] = None, input_format: Optional[str] = None
) -> Tuple[Config, str]:
) -> tuple[Config, str]:
"""
Set up config-realize input.
Expand All @@ -185,8 +185,8 @@ def _realize_config_output_setup(
input_obj: Config,
output_file: Optional[Path] = None,
output_format: Optional[str] = None,
key_path: Optional[List[Union[str, int]]] = None,
) -> Tuple[dict, str]:
key_path: Optional[list[Union[str, int]]] = None,
) -> tuple[dict, str]:
"""
Set up config-realize output.
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/config/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
from pathlib import Path
from typing import List, Optional, Union
from typing import Optional, Union

from jsonschema import Draft202012Validator
from jsonschema.exceptions import ValidationError
Expand Down Expand Up @@ -95,7 +95,7 @@ def _prep_config(config: Union[dict, YAMLConfig, Optional[Path]]) -> YAMLConfig:
return cfgobj


def _validation_errors(config: Union[dict, list], schema: dict) -> List[ValidationError]:
def _validation_errors(config: Union[dict, list], schema: dict) -> list[ValidationError]:
"""
Identify schema-validation errors.
Expand Down
Loading

0 comments on commit 05b9957

Please sign in to comment.