From 7a353612b3abdbfca0efd2ef86aab87d6751ff7e Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Wed, 10 Jul 2024 10:01:42 +0800 Subject: [PATCH] chore: watch docs and template (#650) --- .github/workflows/ci.yml | 2 +- .gitlab/workflows/ci.yml | 2 +- Makefile | 18 ++++--- pdm.lock | 53 +------------------ pyproject.toml | 1 - template/Makefile.jinja | 20 +++---- .../workflows/ci.yml.jinja | 2 +- .../workflows/ci.yml.jinja | 2 +- template/pyproject.toml.jinja | 1 - 9 files changed, 27 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbef7bbe..059071f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: git config --global user.name github-actions git config --global user.email github-actions@github.com - run: pipx install copier==9.3.1 - - run: make consistency + - run: make template-build - run: git diff - run: git status --porcelain - run: test -z "$(git status --porcelain)" diff --git a/.gitlab/workflows/ci.yml b/.gitlab/workflows/ci.yml index 0771ed07..8cf7980c 100644 --- a/.gitlab/workflows/ci.yml +++ b/.gitlab/workflows/ci.yml @@ -39,7 +39,7 @@ consistency: - git config --global user.name gitlab-ci - git config --global user.email gitlab-ci@gitlab.com - pipx install copier==9.3.1 - - make consistency + - make template-build - git diff - git status --porcelain - test -z "$(git status --porcelain)" diff --git a/Makefile b/Makefile index 186e90fb..538b1fd1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-autobuild doc-build doc-coverage doc consistency +.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-watch doc-build doc-coverage doc template-watch template-build ######################################################################################## # Variables @@ -65,6 +65,7 @@ else endif pipx install --force pyproject-fmt==2.1.4 pipx install --force ruff==0.5.1 + pipx install --force watchfiles==0.22.0 ######################################################################################## # Lint and pre-commit @@ -128,15 +129,13 @@ publish: ######################################################################################## # Generate documentation with auto build when changes happen. -doc-autobuild: - pdm run python -m sphinx_autobuild docs $(PUBLIC_DIR) \ - --watch README.md \ - --watch src \ - -a +doc-watch: + pdm run python -m http.server --directory public & + watchfiles "make doc-build" docs src README.md # Build documentation only from src. doc-build: - pdm run python -m sphinx.cmd.build docs $(PUBLIC_DIR) + pdm run sphinx-build -a docs $(PUBLIC_DIR) # Generate html coverage reports with badge. doc-coverage: test-run @@ -150,7 +149,10 @@ doc: doc-build mypy doc-coverage # Template ######################################################################################## -consistency: +template-watch: + watchfiles "make template-build" template includes copier.yaml + +template-build: find . -maxdepth 1 | grep -vE '(\.|\.git|template|includes|copier\.yaml|pdm\.lock)$$' | xargs -I {} rm -r {} copier copy -r HEAD --data-file includes/copier-answers-sample.yml --data repo_platform=gitlab -f . . rm -rf .copier-answers.yml diff --git a/pdm.lock b/pdm.lock index 9114be33..09f5f667 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "doc", "lint", "test"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.2" -content_hash = "sha256:eb5f49b942ac05bcd535904ede8adfa94191ddf9459593bf2c34d729bd725e9f" +content_hash = "sha256:15321cfdb508fccffc1e86ae96141b05b5941404b065576fe758f06f5b123d82" [[package]] name = "alabaster" @@ -194,6 +194,7 @@ version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." groups = ["default", "doc", "test"] +marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -362,20 +363,6 @@ files = [ {file = "jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369"}, ] -[[package]] -name = "livereload" -version = "2.7.0" -requires_python = ">=3.7" -summary = "Python LiveReload is an awesome tool for web developers" -groups = ["doc"] -dependencies = [ - "tornado", -] -files = [ - {file = "livereload-2.7.0-py3-none-any.whl", hash = "sha256:19bee55aff51d5ade6ede0dc709189a0f904d3b906d3ea71641ed548acff3246"}, - {file = "livereload-2.7.0.tar.gz", hash = "sha256:f4ba199ef93248902841e298670eebfe1aa9e148e19b343bc57dbf1b74de0513"}, -] - [[package]] name = "lxml" version = "4.9.3" @@ -1006,22 +993,6 @@ files = [ {file = "sphinx-7.1.2.tar.gz", hash = "sha256:780f4d32f1d7d1126576e0e5ecc19dc32ab76cd24e950228dcf7b1f6d3d9e22f"}, ] -[[package]] -name = "sphinx-autobuild" -version = "2021.3.14" -requires_python = ">=3.6" -summary = "Rebuild Sphinx documentation on changes, with live-reload in the browser." -groups = ["doc"] -dependencies = [ - "colorama", - "livereload", - "sphinx", -] -files = [ - {file = "sphinx-autobuild-2021.3.14.tar.gz", hash = "sha256:de1ca3b66e271d2b5b5140c35034c89e47f263f2cd5db302c9217065f7443f05"}, - {file = "sphinx_autobuild-2021.3.14-py3-none-any.whl", hash = "sha256:8fe8cbfdb75db04475232f05187c776f46f6e9e04cacf1e49ce81bdac649ccac"}, -] - [[package]] name = "sphinx-basic-ng" version = "1.0.0b2" @@ -1144,26 +1115,6 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] -[[package]] -name = "tornado" -version = "6.4.1" -requires_python = ">=3.8" -summary = "Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed." -groups = ["doc"] -files = [ - {file = "tornado-6.4.1-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:163b0aafc8e23d8cdc3c9dfb24c5368af84a81e3364745ccb4427669bf84aec8"}, - {file = "tornado-6.4.1-cp38-abi3-macosx_10_9_x86_64.whl", hash = "sha256:6d5ce3437e18a2b66fbadb183c1d3364fb03f2be71299e7d10dbeeb69f4b2a14"}, - {file = "tornado-6.4.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e2e20b9113cd7293f164dc46fffb13535266e713cdb87bd2d15ddb336e96cfc4"}, - {file = "tornado-6.4.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8ae50a504a740365267b2a8d1a90c9fbc86b780a39170feca9bcc1787ff80842"}, - {file = "tornado-6.4.1-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:613bf4ddf5c7a95509218b149b555621497a6cc0d46ac341b30bd9ec19eac7f3"}, - {file = "tornado-6.4.1-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:25486eb223babe3eed4b8aecbac33b37e3dd6d776bc730ca14e1bf93888b979f"}, - {file = "tornado-6.4.1-cp38-abi3-musllinux_1_2_i686.whl", hash = "sha256:454db8a7ecfcf2ff6042dde58404164d969b6f5d58b926da15e6b23817950fc4"}, - {file = "tornado-6.4.1-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a02a08cc7a9314b006f653ce40483b9b3c12cda222d6a46d4ac63bb6c9057698"}, - {file = "tornado-6.4.1-cp38-abi3-win32.whl", hash = "sha256:d9a566c40b89757c9aa8e6f032bcdb8ca8795d7c1a9762910c722b1635c9de4d"}, - {file = "tornado-6.4.1-cp38-abi3-win_amd64.whl", hash = "sha256:b24b8982ed444378d7f21d563f4180a2de31ced9d8d84443907a0a64da2072e7"}, - {file = "tornado-6.4.1.tar.gz", hash = "sha256:92d3ab53183d8c50f8204a51e6f91d18a15d5ef261e84d452800d4ff6fc504e9"}, -] - [[package]] name = "typer" version = "0.12.3" diff --git a/pyproject.toml b/pyproject.toml index 33204f96..ba531a0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,6 @@ doc = [ "mypy[reports]", "myst-parser", "pytest", - "sphinx-autobuild", "sphinx-click", "sphinx-design", ] diff --git a/template/Makefile.jinja b/template/Makefile.jinja index ba54feeb..1e35534c 100644 --- a/template/Makefile.jinja +++ b/template/Makefile.jinja @@ -1,6 +1,6 @@ [% from pathjoin("includes", "variable.jinja") import page_url with context -%] -.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-autobuild doc-build doc-coverage doc -[%- if project_name == "Serious Scaffold Python" %] consistency[% endif %] +.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-watch doc-build doc-coverage doc +[%- if project_name == "Serious Scaffold Python" %] template-watch template-build[% endif %] ######################################################################################## # Variables @@ -67,6 +67,7 @@ else endif pipx install --force pyproject-fmt==2.1.4 pipx install --force ruff==0.5.1 + pipx install --force watchfiles==0.22.0 ######################################################################################## # Lint and pre-commit @@ -130,15 +131,13 @@ publish: ######################################################################################## # Generate documentation with auto build when changes happen. -doc-autobuild: - pdm run python -m sphinx_autobuild docs $(PUBLIC_DIR) \ - --watch README.md \ - --watch src \ - -a +doc-watch: + pdm run python -m http.server --directory public & + watchfiles "make doc-build" docs src README.md # Build documentation only from src. doc-build: - pdm run python -m sphinx.cmd.build docs $(PUBLIC_DIR) + pdm run sphinx-build -a docs $(PUBLIC_DIR) # Generate html coverage reports with badge. doc-coverage: test-run @@ -153,7 +152,10 @@ doc: doc-build mypy doc-coverage # Template ######################################################################################## -consistency: +template-watch: + watchfiles "make template-build" template includes copier.yaml + +template-build: find . -maxdepth 1 | grep -vE '(\.|\.git|template|includes|copier\.yaml|pdm\.lock)$$' | xargs -I {} rm -r {} copier copy -r HEAD --data-file includes/copier-answers-sample.yml --data repo_platform=gitlab -f . . rm -rf .copier-answers.yml diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja index a1b8eda5..078fdb73 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja @@ -97,7 +97,7 @@ jobs: git config --global user.name github-actions git config --global user.email github-actions@github.com - run: pipx install copier==9.3.1 - - run: make consistency + - run: make template-build - run: git diff - run: git status --porcelain - run: test -z "$(git status --porcelain)" diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index 1f25565c..3d265a46 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -51,7 +51,7 @@ consistency: - git config --global user.name gitlab-ci - git config --global user.email gitlab-ci@gitlab.com - pipx install copier==9.3.1 - - make consistency + - make template-build - git diff - git status --porcelain - test -z "$(git status --porcelain)" diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 2edc93ee..87ff6062 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -94,7 +94,6 @@ doc = [ "mypy[reports]", "myst-parser", "pytest", - "sphinx-autobuild", "sphinx-click", "sphinx-design", ]