diff options
Diffstat (limited to 'nbs/config.ipynb')
| -rw-r--r-- | nbs/config.ipynb | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/nbs/config.ipynb b/nbs/config.ipynb index 9b0be34..18e96db 100644 --- a/nbs/config.ipynb +++ b/nbs/config.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "f0b47680", "metadata": {}, "outputs": [], @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "989dbd8c", "metadata": {}, "outputs": [], @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "id": "5006bc03", "metadata": {}, "outputs": [], @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "id": "645d4349", "metadata": {}, "outputs": [], @@ -61,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "id": "c282bbbc", "metadata": {}, "outputs": [], @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "6c5c3460", "metadata": {}, "outputs": [], @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "id": "7363f5ed", "metadata": {}, "outputs": [], @@ -102,22 +102,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "id": "89f6f072", "metadata": {}, "outputs": [], "source": [ "#| export\n", "def config_dir(curdir:str|Path='.')->Path|None:\n", - " return p.parent if config_path(curdir) is not None else None" + " return Path(curdir).parent if config_path(curdir) is not None else None" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "id": "73f36540", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AssertionError", + "evalue": "config_dir(tmp) != Path(tmp)\n where config_dir(tmp) = PosixPath('/v...dmcw0000gn/T')\n where Path(tmp) = PosixPath('/v.../tmp3p23_l6_')", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mAssertionError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[46]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m TemporaryDirectory() \u001b[38;5;28;01mas\u001b[39;00m tmp:\n\u001b[32m 2\u001b[39m p = Path(tmp)/\u001b[33m'pyproject.toml'\u001b[39m\n\u001b[32m 3\u001b[39m p.touch()\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m test.equal(config_dir(tmp), Path(tmp))\n", + "\u001b[36mFile \u001b[39m\u001b[32m~/src/nb/nb/test.py:87\u001b[39m, in \u001b[36mequal\u001b[39m\u001b[34m(a, b)\u001b[39m\n\u001b[32m 85\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mequal\u001b[39m(a, b):\n\u001b[32m 86\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mAssert that a == b.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m---> \u001b[39m\u001b[32m87\u001b[39m \u001b[30;43mexpect\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43ma\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mb\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43moperator\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43meq\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mnegstr\u001b[39;49m\u001b[30;43m=\u001b[39;49m\u001b[30;43m'\u001b[39;49m\u001b[30;43m!=\u001b[39;49m\u001b[30;43m'\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mframes_up\u001b[39;49m\u001b[30;43m=\u001b[39;49m\u001b[30;43m2\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", + "\u001b[36mFile \u001b[39m\u001b[32m~/src/nb/nb/test.py:77\u001b[39m, in \u001b[36mexpect\u001b[39m\u001b[34m(a, b, cmp, negstr, frames_up, truncate)\u001b[39m\n\u001b[32m 75\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args_src) > \u001b[32m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m a_repr != args_src[\u001b[32m0\u001b[39m]: lines.append(\u001b[33mf\u001b[39m\u001b[33m'\u001b[39m\u001b[33m where \u001b[39m\u001b[38;5;132;01m{\u001b[39;00margs_src[\u001b[32m0\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m = \u001b[39m\u001b[38;5;132;01m{\u001b[39;00ma_repr\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m)\n\u001b[32m 76\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args_src) > \u001b[32m1\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m b_repr != args_src[\u001b[32m1\u001b[39m]: lines.append(\u001b[33mf\u001b[39m\u001b[33m'\u001b[39m\u001b[33m where \u001b[39m\u001b[38;5;132;01m{\u001b[39;00margs_src[\u001b[32m1\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m = \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mb_repr\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m)\n\u001b[32m---> \u001b[39m\u001b[32m77\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m cmp(a, b), \u001b[33m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m.join(lines)\n", + "\u001b[31mAssertionError\u001b[39m: config_dir(tmp) != Path(tmp)\n where config_dir(tmp) = PosixPath('/v...dmcw0000gn/T')\n where Path(tmp) = PosixPath('/v.../tmp3p23_l6_')" + ] + } + ], "source": [ "with TemporaryDirectory() as tmp:\n", " p = Path(tmp)/'pyproject.toml'\n", @@ -171,7 +185,7 @@ "source": [ "#| export\n", "@patch\n", - "def default(cls:Config, base_dir:Path)->Config:\n", + "def default(cls:type[Config], base_dir:Path)->Config:\n", " return cls(**config_defaults(base_dir))" ] }, @@ -184,7 +198,7 @@ "source": [ "#| export\n", "@patch\n", - "def empty(cls:Config)->Config:\n", + "def empty(cls:type[Config])->Config:\n", " return cls(**{f.name:None for f in dataclasses.fields(cls)})" ] }, @@ -208,7 +222,7 @@ "source": [ "#| export\n", "@patch\n", - "def from_dict(cls:Config, d:dict, base_dir:Path)->Config:\n", + "def from_dict(cls:type[Config], d:dict, base_dir:Path)->Config:\n", " d = config_defaults(base_dir) | d\n", " fields = {f.name for f in dataclasses.fields(cls)}\n", " extra = d.keys() - fields\n", @@ -340,7 +354,25 @@ ] } ], - "metadata": {}, + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.14.4" + } + }, "nbformat": 4, "nbformat_minor": 5 } |