-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul of Python architecture (#731)
Fixes #512 Groundwork for #630 & #252 The code has become much simpler in some places (e.g. write_toml). ```python from ribasim import Model m = Model(filepath="generated_testmodels/basic/ribasim.toml") m.database.node.df # Node table m.basin.static.df # BasinStatc table m.write("test") ``` ### Some notes: - The config.py file cannot be autogenerated anymore. The schemas still can, but I disabled it for now to be sure (some imports error). ### Changes: I created new (parent) classes: - BaseModel, from Pydantic, with our own config - FileModel, like hydrolib-core (but now Pydantic v2), which can take a single filepath for initilization. Models who inherit require defining _load and _save, dealing with that filepath. - NodeModel, a class for nodes (where `add` will be). - TableModel, a class to read/write individual tables from/to gpkg/arrow. - SpatialTableModel, inherits TableModel, but reads/writes spatial stuff. I changed: - the Model class to be a carbon copy of Config (which has been deleted), so it mirrors the toml. - in turn this created a `database` NodeModel class (reflecting the field in the toml), with only Node and Edge underneath. - the NodeModel classes Basin from their node_type version to the one in Config, and set the type of the underlying table with a TypeVar like so: ```python class Terminal(NodeModel): static: TableModel[TerminalStaticSchema] ``` ### Yet to do: - [x] Update tests - [x] Fix sort! rules - [x] Delete node_types folder - [x] Link schemas to their Pydantic class (TableModel[TerminalStaticSchema] => TerminalStatic) --------- Co-authored-by: Martijn Visser <[email protected]> Co-authored-by: Hofer-Julian <[email protected]> Co-authored-by: Hofer-Julian <[email protected]>
- Loading branch information
1 parent
d6e585a
commit 633d635
Showing
44 changed files
with
2,742 additions
and
2,951 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
Oops, something went wrong.