From 1a7a1911d3e6613e587f6e2acc22e0caef3b2c24 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 13 Mar 2025 18:11:47 +0000 Subject: [PATCH 01/11] change `strip` to `replace` in module name creation --- src/dash_builder/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dash_builder/cli.py b/src/dash_builder/cli.py index c046018..215d184 100644 --- a/src/dash_builder/cli.py +++ b/src/dash_builder/cli.py @@ -169,7 +169,7 @@ def create_new_page_module(self, template: PageTemplate): def add_view_import_to_init_file(self, template: ViewTemplate): """Add a view import to the init file.""" init_file = template.file_path.parent / "__init__.py" - module_name = template.file_name.strip(".py") + module_name = template.file_name.replace(".py", "") if not init_file.exists(): init_file.write_text('"""Views module."""\n\n__all__ = []\n') From b676f133dc36a07f48366596a8ef2d3106594779 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 13 Mar 2025 18:59:12 +0000 Subject: [PATCH 02/11] enable multiple page and view creation --- src/dash_builder/cli.py | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/dash_builder/cli.py b/src/dash_builder/cli.py index 215d184..abc372a 100644 --- a/src/dash_builder/cli.py +++ b/src/dash_builder/cli.py @@ -213,7 +213,7 @@ def add_view(self, view_name: str): f"[bold green]CREATED[/bold green] {template.class_name} view." ) - def add_page(self, page_name: str, url_path: str): + def add_page(self, page_name: str, url_path: str | None = None): """Add a new page to the project.""" page_path = self.project / "pages" template = PageTemplate(page_name, page_path, url_path) @@ -253,7 +253,9 @@ def build( @app.command("view") def create_view( - view_name: Annotated[str, typer.Argument(help="The name of the view to add.")], + view_names: Annotated[ + list[str], typer.Argument(help="The name of the view(s) to add.") + ], location: Annotated[ str, typer.Option(help="The destination directory for the project.") ] = "", @@ -261,25 +263,47 @@ def create_view( """Add a new view to the project. Args: - view_name: the name of the view to add. + view_names: the name(s) of the view(s) to add. location: the destination directory for the project. """ project = Project.detect(location=location) - project.add_view(view_name) + + for view_name in view_names: + project.add_view(view_name) @app.command("page") def create_page( - page_name: Annotated[str, typer.Argument(help="The name of the page to add.")], - url_path: Annotated[str, typer.Option(help="The URL path of the page.")] = None, + page_names: Annotated[ + list[str], typer.Argument(help="The name of the page(s) to add.") + ], + location: Annotated[ + str, typer.Option(help="The destination directory for the project.") + ] = "", + url_path: Annotated[ + str, + typer.Option( + help="The URL path of the page. Only available for single page creation." + ), + ] = None, ): """Add a new page to the project. Args: - page_name: the name of the page to add. - url_path: the URL path of the page. + page_names: the name of the page to add. + location: the destination directory for the project. + url_path: the URL path of the page. Only available for single page creation. """ - project = Project.detect() - project.add_page(page_name, url_path) + project = Project.detect(location=location) + if len(page_names) > 1: + if url_path: + project.console.print( + "[bold red]ERROR[/bold red] URL path is only available for single page creation." + ) + return + for page_name in page_names: + project.add_page(page_name) + else: + project.add_page(page_names[0], url_path) From 825f96c4bf32cc1b634acc3f188a431479efaa4f Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 13 Mar 2025 20:24:03 +0000 Subject: [PATCH 03/11] improve error container rendering --- src/dash_builder/_dash_object.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dash_builder/_dash_object.py b/src/dash_builder/_dash_object.py index 80227f4..1f149c8 100644 --- a/src/dash_builder/_dash_object.py +++ b/src/dash_builder/_dash_object.py @@ -4,6 +4,7 @@ import re import traceback +import dash_mantine_components as dmc from dash import html __all__ = ["DashObject"] @@ -54,7 +55,14 @@ def error_container(cls, message: str) -> html.Div: `dash.html.Div` container. """ - return html.Div(html.Pre(message)) + return dmc.Container( + dmc.Code( + message, + block=True, + color="var(--mantine-color-red-2)", + style={"whiteSpace": "pre-wrap"}, + ) + ) @classmethod @abc.abstractmethod From 846b0d8ac5cd923b52783f4255138dfdc1905e13 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 13 Mar 2025 20:28:53 +0000 Subject: [PATCH 04/11] update test for error check --- tests/test_dash_page.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_dash_page.py b/tests/test_dash_page.py index 3c2fb06..4bb9878 100644 --- a/tests/test_dash_page.py +++ b/tests/test_dash_page.py @@ -2,6 +2,7 @@ import pytest from dash import html +import dash_mantine_components as dmc from src.dash_builder import DashPage @@ -10,8 +11,8 @@ def test_page_error(test_page): container = test_page.error_container("test message") inner = container.children inner_text = inner.children - assert isinstance(container, html.Div) - assert isinstance(inner, html.Pre) + assert isinstance(container, dmc.Container) + assert isinstance(inner, dmc.Code) assert inner_text == "test message" @@ -19,8 +20,8 @@ def test_page_on_error(error_page): container = error_page.layout() inner = container.children inner_text = inner.children - assert isinstance(container, html.Div) - assert isinstance(inner, html.Pre) + assert isinstance(container, dmc.Container) + assert isinstance(inner, dmc.Code) assert "ZeroDivisionError: division by zero" in inner_text From b3944c36fb31881d6d7bebbec6670f33b357ca50 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 13 Mar 2025 20:28:58 +0000 Subject: [PATCH 05/11] formatting --- src/dash_builder/examples/basic-mantine/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dash_builder/examples/basic-mantine/app.py b/src/dash_builder/examples/basic-mantine/app.py index 4a751e0..4edcfd4 100644 --- a/src/dash_builder/examples/basic-mantine/app.py +++ b/src/dash_builder/examples/basic-mantine/app.py @@ -5,9 +5,9 @@ import dash import dash_mantine_components as dmc from typing_extensions import override -from views import FooterView, HeaderView, SidebarView from dash_builder import DashPage +from views import FooterView, HeaderView, SidebarView dash._dash_renderer._set_react_version("18.2.0") From 7b0c6ba7160c17433b2dbde347087a9b7e8e4d90 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 20 Mar 2025 18:35:55 +0000 Subject: [PATCH 06/11] add location component to track URL --- src/dash_builder/examples/basic-mantine/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dash_builder/examples/basic-mantine/app.py b/src/dash_builder/examples/basic-mantine/app.py index 4edcfd4..7cde43a 100644 --- a/src/dash_builder/examples/basic-mantine/app.py +++ b/src/dash_builder/examples/basic-mantine/app.py @@ -4,6 +4,7 @@ import dash import dash_mantine_components as dmc +from dash import dcc from typing_extensions import override from dash_builder import DashPage @@ -293,6 +294,7 @@ def valid_layout(cls, **kwargs): SidebarView.layout("sidebar"), dmc.AppShellMain(dash.page_container), FooterView.layout("footer"), + dcc.Location(id="url"), ], header={"height": 60}, footer={"height": 30}, From c8cefc9cb5a08c73ab72f8409b78fdcdb8f92e42 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 20 Mar 2025 20:17:56 +0000 Subject: [PATCH 07/11] remove `pdoc` and add `mkdocs` --- docs/index.md | 17 +++++++++++++++++ mkdocs.yml | 1 + pyproject.toml | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 docs/index.md create mode 100644 mkdocs.yml diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..000ea34 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,17 @@ +# Welcome to MkDocs + +For full documentation visit [mkdocs.org](https://www.mkdocs.org). + +## Commands + +* `mkdocs new [dir-name]` - Create a new project. +* `mkdocs serve` - Start the live-reloading docs server. +* `mkdocs build` - Build the documentation site. +* `mkdocs -h` - Print help message and exit. + +## Project layout + + mkdocs.yml # The configuration file. + docs/ + index.md # The documentation homepage. + ... # Other markdown pages, images and other files. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..c97182f --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1 @@ +site_name: My Docs diff --git a/pyproject.toml b/pyproject.toml index 024dda1..65cb537 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,12 @@ venvPath = "." venv = ".venv" [dependency-groups] -dev = ["pdoc>=15.0.1", "pytest>=8.3.4", "pytest-cov>=6.0.0", "ruff>=0.9.7"] +dev = [ + "mkdocs>=1.6.1", + "pytest>=8.3.4", + "pytest-cov>=6.0.0", + "ruff>=0.9.7", +] [tool.ruff] # Exclude a variety of commonly ignored directories. From b875c7a9e18c8ca2136d48ebd5f37b6eea3c3b63 Mon Sep 17 00:00:00 2001 From: robfs Date: Thu, 20 Mar 2025 20:20:47 +0000 Subject: [PATCH 08/11] add mkdocs material theme --- mkdocs.yml | 2 ++ pyproject.toml | 1 + 2 files changed, 3 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index c97182f..04381ed 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1 +1,3 @@ site_name: My Docs +theme: + name: material \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 65cb537..01826e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ venv = ".venv" [dependency-groups] dev = [ "mkdocs>=1.6.1", + "mkdocs-material>=9.6.9", "pytest>=8.3.4", "pytest-cov>=6.0.0", "ruff>=0.9.7", From c402f97d6255f7addb388ca5f7a1961ea4fd5ae1 Mon Sep 17 00:00:00 2001 From: robfs Date: Fri, 21 Mar 2025 20:44:19 +0000 Subject: [PATCH 09/11] add extra mkdocs plugins --- docs/index.md | 17 +++++++++++++++++ mkdocs.yml | 5 ++++- pyproject.toml | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 000ea34..b2a6e79 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,3 +15,20 @@ For full documentation visit [mkdocs.org](https://www.mkdocs.org). docs/ index.md # The documentation homepage. ... # Other markdown pages, images and other files. + +## Termynal + + + +``` +$ uv -h + +... +``` + +::: dash_builder.dash_page.DashPage + options: + members: + - valid_layout + - layout + inherited_members: true diff --git a/mkdocs.yml b/mkdocs.yml index 04381ed..30109fa 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,6 @@ site_name: My Docs theme: - name: material \ No newline at end of file + name: material +plugins: + - termynal + - mkdocstrings diff --git a/pyproject.toml b/pyproject.toml index 01826e2..bc6b090 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,9 +29,11 @@ venv = ".venv" dev = [ "mkdocs>=1.6.1", "mkdocs-material>=9.6.9", + "mkdocstrings-python>=1.16.7", "pytest>=8.3.4", "pytest-cov>=6.0.0", "ruff>=0.9.7", + "termynal>=0.13.0", ] [tool.ruff] From 9a48656ba46ebe624d4d5f5342c10e9f91a8ebdd Mon Sep 17 00:00:00 2001 From: robfs Date: Fri, 21 Mar 2025 20:44:31 +0000 Subject: [PATCH 10/11] update documentation pipeline to mkdocs --- .github/workflows/{pdoc.yaml => publish-docs.yaml} | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) rename .github/workflows/{pdoc.yaml => publish-docs.yaml} (79%) diff --git a/.github/workflows/pdoc.yaml b/.github/workflows/publish-docs.yaml similarity index 79% rename from .github/workflows/pdoc.yaml rename to .github/workflows/publish-docs.yaml index ae7d9c2..b56e4c2 100644 --- a/.github/workflows/pdoc.yaml +++ b/.github/workflows/publish-docs.yaml @@ -24,16 +24,12 @@ jobs: - uses: actions/setup-python@v5 with: python-version-file: ".python-version" - - # ADJUST THIS: install all dependencies (including pdoc) - run: uv sync --all-extras --dev - # ADJUST THIS: build your documentation into docs/. - # We use a custom build script for pdoc itself, ideally you just run `pdoc -o docs/ ...` here. - - run: uv run pdoc src/dash_builder -o docs/ + - run: uv run mkdocs build - uses: actions/upload-pages-artifact@v3 with: - path: docs/ + path: site/ # Deploy the artifact to GitHub pages. # This is a separate job so that only actions/deploy-pages has the necessary permissions. From a2c279d59671ac8eebc1f1445642b9bce9c7b9af Mon Sep 17 00:00:00 2001 From: robfs Date: Fri, 21 Mar 2025 20:53:17 +0000 Subject: [PATCH 11/11] increment version number --- pyproject.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bc6b090..c5a6948 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dash-builder" -version = "0.1.4" +version = "0.1.5" description = "A tool and framework to simplify construction of Python Dash applications." readme = "README.md" authors = [{ name = "robfs", email = "robfoxsimms@gmail.com" }] @@ -27,13 +27,13 @@ venv = ".venv" [dependency-groups] dev = [ - "mkdocs>=1.6.1", - "mkdocs-material>=9.6.9", - "mkdocstrings-python>=1.16.7", - "pytest>=8.3.4", - "pytest-cov>=6.0.0", - "ruff>=0.9.7", - "termynal>=0.13.0", + "mkdocs>=1.6.1", + "mkdocs-material>=9.6.9", + "mkdocstrings-python>=1.16.7", + "pytest>=8.3.4", + "pytest-cov>=6.0.0", + "ruff>=0.9.7", + "termynal>=0.13.0", ] [tool.ruff]