From 8b1a047d31959f5fc8afa43e1802bde2363c30a5 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Tue, 15 Oct 2024 13:27:11 -0400 Subject: [PATCH] cleanup --- flopy/mf6/utils/codegen/context.py | 10 +++------- flopy/mf6/utils/codegen/make.py | 6 ++---- flopy/mf6/utils/codegen/ref.py | 9 ++++----- flopy/mf6/utils/codegen/render.py | 12 ++++++------ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/flopy/mf6/utils/codegen/context.py b/flopy/mf6/utils/codegen/context.py index cf51c07ea..77318d010 100644 --- a/flopy/mf6/utils/codegen/context.py +++ b/flopy/mf6/utils/codegen/context.py @@ -25,11 +25,7 @@ class Context: Notes ----- - A context class minimally consists of a name, a definition, and a - map of variables. The definition and variables are redundant (the - latter are generated from the former) but for now, the definition - is needed. When generated classes no longer reproduce definitions - verbatim, it can be removed. + A context minimally consists of a name and a map of variables. The context class may inherit from a base class, and may specify a parent context within which it can be created (the parent then @@ -58,6 +54,8 @@ class Name(NamedTuple): - a description of the context class - the name of the source file to write - the base class the context inherits from + - the name of the parent parameter in the context + class' `__init__` method, if it can have a parent """ @@ -183,9 +181,7 @@ def from_dfn(cls, dfn: Dfn) -> Iterator["Context"]: """ Extract context class descriptor(s) from an input definition. These are structured representations of input context classes. - Each input definition yields one or more input contexts. - The `name` parameter can be used to select the context. """ meta = dfn.meta.copy() diff --git a/flopy/mf6/utils/codegen/make.py b/flopy/mf6/utils/codegen/make.py index 3d18ca517..74af3b70e 100644 --- a/flopy/mf6/utils/codegen/make.py +++ b/flopy/mf6/utils/codegen/make.py @@ -40,8 +40,7 @@ def make_all(dfndir: Path, outdir: Path, verbose: bool = False): with open(common_path, "r") as f: common, _ = Dfn._load(f) - # load subpackages first so we can pass them as references - # to load() for the rest of the input contexts + # load subpackage references first refs: Refs = {} for path in paths: name = Dfn.Name(*path.stem.split("-")) @@ -51,8 +50,7 @@ def make_all(dfndir: Path, outdir: Path, verbose: bool = False): if ref: refs[ref.key] = ref - # load all the input definitions before we generate input - # contexts so we can create foreign key refs between them. + # load all the input definitions dfns: Dfns = {} for path in paths: name = Dfn.Name(*path.stem.split("-")) diff --git a/flopy/mf6/utils/codegen/ref.py b/flopy/mf6/utils/codegen/ref.py index 59a2c067e..2637f0ba3 100644 --- a/flopy/mf6/utils/codegen/ref.py +++ b/flopy/mf6/utils/codegen/ref.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Dict, List, Optional +from typing import Dict, Optional from warnings import warn from flopy.mf6.utils.codegen.dfn import Dfn @@ -12,10 +12,9 @@ class Ref: and another input definition. This allows an input context to refer to another input context, by including a filepath variable whose name acts as a foreign key for a different - input context. Extra parameters are added to the referring - context's `__init__` method so a selected "value" variable - defined in the referenced context can be provided directly - instead of the file path (foreign key) variable. + input context. The referring context's `__init__` method + is modified such that the variable named `val` replaces + the `key` variable. Notes ----- diff --git a/flopy/mf6/utils/codegen/render.py b/flopy/mf6/utils/codegen/render.py index 345c11016..af8075cc2 100644 --- a/flopy/mf6/utils/codegen/render.py +++ b/flopy/mf6/utils/codegen/render.py @@ -2,10 +2,10 @@ from enum import Enum from typing import Any, Callable, Dict, Iterable, Optional, Tuple -_Predicate = Callable[[Any], bool] -_Transform = Callable[[Any], Dict[str, str]] -_Pair = Tuple[str, Any] -_Pairs = Iterable[_Pair] +Predicate = Callable[[Any], bool] +Transform = Callable[[Any], Dict[str, str]] +Pair = Tuple[str, Any] +Pairs = Iterable[Pair] def _try_get_enum_value(v: Any) -> Any: @@ -17,8 +17,8 @@ def renderable( *, keep_none: Optional[Iterable[str]] = None, quote_str: Optional[Iterable[str]] = None, - set_pairs: Optional[Iterable[Tuple[_Predicate, _Pairs]]] = None, - transform: Optional[Iterable[Tuple[_Predicate, _Transform]]] = None, + set_pairs: Optional[Iterable[Tuple[Predicate, Pairs]]] = None, + transform: Optional[Iterable[Tuple[Predicate, Transform]]] = None, ): """ Decorator for dataclasses which are meant