aboutsummaryrefslogtreecommitdiffstats
path: root/nbs/config.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'nbs/config.ipynb')
-rw-r--r--nbs/config.ipynb34
1 files changed, 29 insertions, 5 deletions
diff --git a/nbs/config.ipynb b/nbs/config.ipynb
index 5897a37..9b0be34 100644
--- a/nbs/config.ipynb
+++ b/nbs/config.ipynb
@@ -135,8 +135,8 @@
"#| export\n",
"@dataclasses.dataclass\n",
"class Config:\n",
- " nb_dir:str|None\n",
- " export_dir:str|None"
+ " nb_dir:str|Path|None\n",
+ " export_dir:str|Path|None"
]
},
{
@@ -178,6 +178,30 @@
{
"cell_type": "code",
"execution_count": null,
+ "id": "667948b3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#| export\n",
+ "@patch\n",
+ "def empty(cls:Config)->Config:\n",
+ " return cls(**{f.name:None for f in dataclasses.fields(cls)})"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "97fc77c3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "empty = Config.empty()\n",
+ "test.equal(empty, Config(nb_dir=None, export_dir=None))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
"id": "d95dafba",
"metadata": {},
"outputs": [],
@@ -232,9 +256,9 @@
"outputs": [],
"source": [
"#| export\n",
- "def get_config(curdir:str|Path='.')->Config|None:\n",
+ "def get_config(curdir:str|Path='.')->Config:\n",
" p = config_path(curdir)\n",
- " if not p: return None\n",
+ " if not p: return Config.empty()\n",
" nb = tomllib.loads(p.read_text()).get('tool', {}).get('nb', {})\n",
" return Config.from_dict(nb, base_dir=p.parent)"
]
@@ -247,7 +271,7 @@
"outputs": [],
"source": [
"with TemporaryDirectory() as tmp:\n",
- " test.equal(get_config(tmp), None)"
+ " test.equal(get_config(tmp), Config.empty())"
]
},
{