ipython / ipython/traitlets

Nested configurables

未關閉
#421 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
653
分支
217
平均合併
2 天 21 小時
30 天內合併 PR
2

描述

We're looking to use traitlets to enforce type checking in the configuration of a coastal ocean model thetis (github.com/thetisproject/thetis).

Right now, we have a tree of configuration options. For example:
```
ModelOptions:
turbulence_model = "some_value"
turbulence_model_options = TurbulenceModelOptions
```

Right now, we just use nested dictionaries for this.

It seems like one would like to have a `Configurable` with traits that are themselves `Configurable` objects:

right now we use:

```python
class TurbulenceModelOptions(Configurable):
pass

class GLSOptions(TurbulenceModelOptions):
use_hyperviscosity = Bool()

class SmagorinskyOptions(TurbulenceModelOptions):
background_viscosity = Float()

class ModelOptions(Configurable):
turbulence_model = Enum(["gls", "smagorinsky"])
turbulence_model_options = Instance(TurbulenceModelOptions)
```

But generating (for example) rST doesn't recurse into the trait values, so the presentation of the options isn't right.

Are we doing this wrong? Is there some more obvious way of glueing together such a hierarchy?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。