Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Oct 15, 2024
1 parent 4cdf826 commit 8b1a047
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
10 changes: 3 additions & 7 deletions flopy/mf6/utils/codegen/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions flopy/mf6/utils/codegen/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("-"))
Expand All @@ -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("-"))
Expand Down
9 changes: 4 additions & 5 deletions flopy/mf6/utils/codegen/ref.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
-----
Expand Down
12 changes: 6 additions & 6 deletions flopy/mf6/utils/codegen/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 8b1a047

Please sign in to comment.