Conversation
|
@jacobcook1995 and @vgro and I discussed this recently so I haven't added them as reviewers, but it would be great to get a check for any issues. @TaranRallings is ill. |
Codecov Report
@@ Coverage Diff @@
## develop #173 +/- ##
===========================================
- Coverage 95.23% 94.99% -0.25%
===========================================
Files 19 19
Lines 966 959 -7
===========================================
- Hits 920 911 -9
- Misses 46 48 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
If possible could you update the documentation in |
|
That occurred to me too. I was going to lazily change it when I update the |
alexdewar
left a comment
There was a problem hiding this comment.
Looks ok to me. I've made a suggestion.
| @@ -217,23 +255,3 @@ def schema() -> dict: | |||
|
|
|||
| return config_schema | |||
| ``` | |||
There was a problem hiding this comment.
Is this code the same for all models, except for the name of the schema file?
If so, you could remove some of the boilerplate and just do something like this in all the __init__.py files:
from virtual_rainforest.core.config import default_schema_setup
schema = default_schema_setup()You'll probably need to examine the stack for this.
There was a problem hiding this comment.
It is the same for all models. That's a good thought.
| # from virtual_rainforest.models.soil.model import SoilModel # noqa: F401 | ||
| # - define a schema member, decorated with @register_schema | ||
| for module_info in pkgutil.iter_modules(vfm.__path__): | ||
| import_module(f"virtual_rainforest.models.{module_info.name}") |
There was a problem hiding this comment.
...alternatively, you could check here whether the module has an attribute called schema and if not, add a default one.
There was a problem hiding this comment.
One thing that crossed my mind was having a config.add_module command which basically wraps this import and schema registration. That could then be used to add custom modules outside of the package tree. If you're at the Python command line, you can always import them, but if you wanted to use them in a config, we'd need a custom_model section that could use this too. But, that is probably one for the future.
|
I have updated this PR to implement Alex's suggestion of having a function to setup the schema. I've basically moved all of the reading and validation out of model I've updated the user docs and docstrings and then patched all the existing |
jacobcook1995
left a comment
There was a problem hiding this comment.
LGTM, made some minor comments but nothing major
Description
This PR adds model autodiscovery to the
virtual_rainforest/__init__.pyfile.Any submodule within
virtual_rainforests/modelswill automatically get its schema and BaseModel subclass registered, as long as the model__init__.pycontains the schema registration and imports its BaseModel. The PR also updates the existingsoilandabioticmodules to implement that requirement.The other advantage here is that the import path for the main models is shorter. That seems like a sensible thing for the core object in each model:
rather than:
Fixes #172
ETA: Fixes #167
Type of change
Key checklist
pre-commitchecks:$ pre-commit run -a$ poetry run pytestFurther checks