ImperialCollegeLondon / ImperialCollegeLondon/SWMManywhere
`config` structure
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 51
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
> Since have nested and rather complex config structure, this approach is not suitable. You should have a custom class for this using `dataclass` for example, since working with nested dict objects is difficult and not maintainable. I know you're in a time crunch and want to produce results as soon as possible. But I highly recommend refactoring this part. So, for example, instead of having `config['real']['results']`, you can have something like this:
```python
@dataclass
class RealModel:
inp: Path
graph: Path
subcatchments: Path
results: Path
def __post_init__(self)->None:
self.inp = Path(self.inp)
self.graph = Path(self.inp)
self.subcatchments = Path(self.inp)
self.results = Path(self.inp)
for f in (self.inp, self.graph, self.subcatchments, self.results):
if not f.exists():
raise FileNotFoundError(f)
@dataclass
class ModelConfig:
real: RealModel
```
> So, whenever you want to use it in the code, you can use `config.real.results`. You can have validations and conversions, if necessary, in `__post_init__`. Having a structure for config even makes development and maintenance easier, since most IDEs now use them for autocomplete suggestions and static type checkers will be able to catch errors.
> As I said, if you don't have time to refactor this now, it's ok, it's not a blocker for me.
_Originally posted by @cheginit in https://github.com/ImperialCollegeLondon/SWMManywhere/pull/83#discussion_r1526522626_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Locate where the nested configuration is constructed and accessed, then assess the proposed Python dataclass structure and its validation needs. Done means configuration access no longer depends on the difficult-to-maintain nested dictionary structure and existing behavior remains covered by the project's tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100