From 688b838d1df5c601db71b45590b1c212175f9f34 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 23 May 2026 21:31:22 +0000 Subject: Add support for using cfg in clean/export cli cmds --- nbs/config.ipynb | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'nbs/config.ipynb') 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" ] }, { @@ -175,6 +175,30 @@ " return cls(**config_defaults(base_dir))" ] }, + { + "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, @@ -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())" ] }, { -- cgit v1.2.3