From 356275d469b8b1c1739399361d52483d89f86aa4 Mon Sep 17 00:00:00 2001 From: martonvago Date: Mon, 4 Aug 2025 17:00:11 +0100 Subject: [PATCH 1/3] refactor: :recycle: update config for non-template package --- .github/workflows/build-website.yml | 2 +- .gitignore | 35 -------------- .vscode/extensions.json | 4 -- .vscode/settings.json | 12 ++--- _publish.yml | 2 +- justfile | 72 ++++------------------------- 6 files changed, 16 insertions(+), 111 deletions(-) diff --git a/.github/workflows/build-website.yml b/.github/workflows/build-website.yml index b24f3c4..82630a5 100644 --- a/.github/workflows/build-website.yml +++ b/.github/workflows/build-website.yml @@ -10,7 +10,7 @@ permissions: read-all jobs: build-website: - uses: seedcase-project/.github/.github/workflows/reusable-build-docs-with-python.yml@main + uses: seedcase-project/.github/.github/workflows/reusable-build-docs.yml@main secrets: netlify-token: ${{ secrets.NETLIFY_AUTH_TOKEN }} # This is to allow using `gh` CLI diff --git a/.gitignore b/.gitignore index 6346a65..c5fe006 100644 --- a/.gitignore +++ b/.gitignore @@ -26,41 +26,6 @@ venv __pycache__/ *.py[cod] -# Python packaging and distribution -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# Python testing and code coverage -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -coverage.* -.cache -nosetests.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - # MacOS .DS_Store diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 5377c5f..184eca4 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,13 +7,9 @@ "felipecaputo.git-project-manager", "GitHub.vscode-pull-request-github", "ms-python.python", - "ms-python.vscode-pylance", - "matangover.mypy", - "njpwerner.autodocstring", "quarto.quarto", "ms-toolsai.jupyter", "vivaxy.vscode-conventional-commits", - "charliermarsh.ruff", "pshaddel.conventional-branch", "tekumara.typos-vscode", "EditorConfig.EditorConfig" diff --git a/.vscode/settings.json b/.vscode/settings.json index 0e5bf35..fc0bb11 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,13 +26,13 @@ "[quarto][qmd]": { "editor.formatOnSave": false }, - "[python]": { - "editor.defaultFormatter": "charliermarsh.ruff" - }, "python.defaultInterpreterPath": "${workspaceFolder}/.venv", "python.languageServer": "Pylance", "files.insertFinalNewline": true, - "python.testing.pytestEnabled": true, - "python.testing.pytestPath": "${workspaceFolder}/.venv/bin/pytest", - "mypy.runUsingActiveInterpreter": true, + "files.associations": { + "*.yml.jinja": "jinja-yaml", + "*.cff.jinja": "jinja-yaml", + "*.toml.jinja": "jinja-toml", + "*.qmd.jinja": "jinja-md" + }, } diff --git a/_publish.yml b/_publish.yml index 1974aab..6f62199 100644 --- a/_publish.yml +++ b/_publish.yml @@ -2,4 +2,4 @@ netlify: # TODO: Include correct ID - id: "" - url: "https://NAME-seedcase-project.netlify.app" + url: "https://seedcase-template-python-package.netlify.app" diff --git a/justfile b/justfile index b009dfd..ae73fb3 100644 --- a/justfile +++ b/justfile @@ -2,7 +2,7 @@ just --list --unsorted # Run all build-related recipes in the justfile -run-all: install-deps format-python check-python check-unused test-python check-security check-spelling check-commits build-website +run-all: check-spelling check-commits build-website # Install the pre-commit hooks install-precommit: @@ -13,78 +13,22 @@ install-precommit: # Update versions of pre-commit hooks uvx pre-commit autoupdate -# Install Python package dependencies -install-deps: - uv sync --all-extras --dev - -# Run the Python tests -test-python: - uv run pytest - # Make the badge from the coverage report - uv run genbadge coverage \ - -i coverage.xml \ - -o htmlcov/coverage.svg - -# Check Python code for any errors that need manual attention -check-python: - # Check formatting - uv run ruff check . - # Check types - uv run mypy . - -# Reformat Python code to match coding style and general structure -format-python: - uv run ruff check --fix . - uv run ruff format . - -# Build the documentation website using Quarto -build-website: - # To let Quarto know where python is. - export QUARTO_PYTHON=.venv/bin/python3 - # Delete any previously built files from quartodoc. - # -f is to not give an error if the files don't exist yet. - rm -f docs/reference/*.qmd - uv run quartodoc build - uv run quarto render --execute - -# Run checks on commits with non-main branches +# Check the commit messages on the current branch that are not on the main branch check-commits: #!/bin/zsh branch_name=$(git rev-parse --abbrev-ref HEAD) number_of_commits=$(git rev-list --count HEAD ^main) if [[ ${branch_name} != "main" && ${number_of_commits} -gt 0 ]] then - uv run cz check --rev-range main..HEAD + uvx --from commitizen cz check --rev-range main..HEAD else - echo "Can't either be on ${branch_name} or have more than ${number_of_commits}." + echo "On `main` or current branch doesn't have any commits." fi -# Run basic security checks on the package -check-security: - uv run bandit -r src/ - # Check for spelling errors in files check-spelling: - uv run typos + uvx typos -# Build the documentation as PDF using Quarto -build-pdf: - # To let Quarto know where python is. - export QUARTO_PYTHON=.venv/bin/python3 - uv run quarto install tinytex - # For generating images from Mermaid diagrams - uv run quarto install chromium - uv run quarto render --profile pdf --to pdf - find docs -name "mermaid-figure-*.png" -delete - -# Check for unused code in the package and its tests -check-unused: - # exit code=0: No unused code was found - # exit code=3: Unused code was found - # Three confidence values: - # - 100 %: function/method/class argument, unreachable code - # - 90 %: import - # - 60 %: attribute, class, function, method, property, variable - # There are some things should be ignored though, with the allowlist. - # Create an allowlist with `vulture --make-allowlist` - uv run vulture src/ tests/ **/vulture-allowlist.py +# Build the website using Quarto +build-website: + uvx --from quarto quarto render From e3f9cc85ec3caed7e61f110cd726b5eefbc6a4dd Mon Sep 17 00:00:00 2001 From: martonvago Date: Tue, 5 Aug 2025 11:36:54 +0100 Subject: [PATCH 2/3] build: :wrench: match template-website justfile --- README.md | 14 +++++++++++--- README.qmd | 23 +++++++++++++++++++++++ justfile | 35 ++++++++++++++++++++++++++++++++++- tools/get-contributors.sh | 18 ++++++++++++++++++ 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 README.qmd create mode 100644 tools/get-contributors.sh diff --git a/README.md b/README.md index 39e8d23..364c88b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ + + # Template for Seedcase Python packages -This repository contains a template for setting up new Python package projects in Seedcase. The first step is to create a new repository using this template. This can easily be done by clicking the "Use this template" button on the repository page or by using the GitHub CLI: +This repository contains a template for setting up new Python package +projects in Seedcase. The first step is to create a new repository using +this template. This can easily be done by clicking the “Use this +template” button on the repository page or by using the GitHub CLI: ``` bash # NAME is the name to give the new repository @@ -9,11 +14,14 @@ gh repo create NAME --template seedcase-project/template-python-project ## Setting things up after cloning -Search for `NAME` and `REPO` and replace them with the name of your project and the repository name. Then look for any `TODO` items. +Search for `NAME` and `REPO` and replace them with the name of your +project and the repository name. Then look for any `TODO` items. ## Setting things up -Use the commands found in [`spaid`](https://github.com/seedcase-project/spaid) repo to run the next setup steps. +Use the commands found in +[`spaid`](https://github.com/seedcase-project/spaid) repo to run the +next setup steps. Need to install these packages after: diff --git a/README.qmd b/README.qmd new file mode 100644 index 0000000..39e8d23 --- /dev/null +++ b/README.qmd @@ -0,0 +1,23 @@ +# Template for Seedcase Python packages + +This repository contains a template for setting up new Python package projects in Seedcase. The first step is to create a new repository using this template. This can easily be done by clicking the "Use this template" button on the repository page or by using the GitHub CLI: + +``` bash +# NAME is the name to give the new repository +gh repo create NAME --template seedcase-project/template-python-project +``` + +## Setting things up after cloning + +Search for `NAME` and `REPO` and replace them with the name of your project and the repository name. Then look for any `TODO` items. + +## Setting things up + +Use the commands found in [`spaid`](https://github.com/seedcase-project/spaid) repo to run the next setup steps. + +Need to install these packages after: + +``` bash +uv add --dev pre-commit ruff typos pytest bandit commitizen \ + genbadge jupyter pytest-cov quartodoc +``` diff --git a/justfile b/justfile index ae73fb3..0849692 100644 --- a/justfile +++ b/justfile @@ -1,8 +1,11 @@ @_default: just --list --unsorted +@_checks: check-spelling check-commits +@_builds: build-contributors build-website build-readme + # Run all build-related recipes in the justfile -run-all: check-spelling check-commits build-website +run-all: update-quarto-theme update-template _checks test _builds # Install the pre-commit hooks install-precommit: @@ -13,6 +16,18 @@ install-precommit: # Update versions of pre-commit hooks uvx pre-commit autoupdate +# Update the Quarto seedcase-theme extension +update-quarto-theme: + quarto add seedcase-project/seedcase-theme --no-prompt + +# Update files in the template from the copier parent folder +update-template: + cp .cz.toml .pre-commit-config.yaml .typos.toml .editorconfig template/ + mkdir -p template/tools + cp tools/get-contributors.sh template/tools/ + cp .github/pull_request_template.md template/.github/ + cp .github/workflows/build-website.yml .github/workflows/dependency-review.yml template/.github/workflows/ + # Check the commit messages on the current branch that are not on the main branch check-commits: #!/bin/zsh @@ -29,6 +44,24 @@ check-commits: check-spelling: uvx typos +# Test and check that a Python package can be created from the template +# TODO: add test for copier +test: + echo "copier test" + +# Clean up any leftover and temporary build files +cleanup: + #!/bin/zsh + rm -rf _temp + # Build the website using Quarto build-website: uvx --from quarto quarto render + +# Re-build the README file from the Quarto version +build-readme: + uvx --from quarto quarto render README.qmd --to gfm + +# Generate a Quarto include file with the contributors +build-contributors: + sh ./tools/get-contributors.sh seedcase-project/template-workshop diff --git a/tools/get-contributors.sh b/tools/get-contributors.sh new file mode 100644 index 0000000..65bfbb4 --- /dev/null +++ b/tools/get-contributors.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Get a list of contributors to this repository and save it to +# _contributors.qmd.tmp file. It also: +# +# - Formats users into Markdown links to their GitHub profiles. +# - Removes any usernames with the word "bot" in them. +# - Removes the trailing comma from the list. +repo_spec=${1} +echo "These are the people who have contributed by submitting changes through pull requests :tada:\n\n" > _contributors.qmd.tmp +gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/$repo_spec/contributors \ + --template '{{range .}} [\@{{.login}}]({{.html_url}}){{"\n"}}{{end}}' | \ + grep -v "\[bot\]" | \ + tr '\n' ', ' | \ + sed -e 's/,$//' >> _contributors.qmd.tmp From af6b8a2415b3ff70a3a709726b97468d01b2e8c2 Mon Sep 17 00:00:00 2001 From: martonvago <57952344+martonvago@users.noreply.github.com> Date: Tue, 5 Aug 2025 11:44:51 +0100 Subject: [PATCH 3/3] build: :wrench: add Netlify ID Co-authored-by: Luke W. Johnston --- _publish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_publish.yml b/_publish.yml index 6f62199..c450276 100644 --- a/_publish.yml +++ b/_publish.yml @@ -1,5 +1,4 @@ - source: project netlify: - # TODO: Include correct ID - - id: "" + - id: "8775b18b-3a1a-4dfc-b6c7-a1ef7205d30f" url: "https://seedcase-template-python-package.netlify.app"