Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:

Expand Down
23 changes: 23 additions & 0 deletions README.qmd
Original file line number Diff line number Diff line change
@@ -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
```
5 changes: 2 additions & 3 deletions _publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- source: project
netlify:
# TODO: Include correct ID
- id: ""
url: "https://NAME-seedcase-project.netlify.app"
- id: "8775b18b-3a1a-4dfc-b6c7-a1ef7205d30f"
url: "https://seedcase-template-python-package.netlify.app"
99 changes: 38 additions & 61 deletions justfile
Comment thread
martonvago marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -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: install-deps format-python check-python check-unused test-python check-security check-spelling check-commits build-website
run-all: update-quarto-theme update-template _checks test _builds

# Install the pre-commit hooks
install-precommit:
Expand All @@ -13,78 +16,52 @@ 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 .
# Update the Quarto seedcase-theme extension
update-quarto-theme:
quarto add seedcase-project/seedcase-theme --no-prompt

# Reformat Python code to match coding style and general structure
format-python:
uv run ruff check --fix .
uv run ruff format .
# 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/
Comment on lines +24 to +29
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only bit I changed from the template-website version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build website workflow may need to be removed. But we can deal with that later, as you add the copier.yaml file and the questions in it.


# 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

# 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

# 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
# Re-build the README file from the Quarto version
build-readme:
uvx --from quarto quarto render README.qmd --to gfm

# 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
# Generate a Quarto include file with the contributors
build-contributors:
sh ./tools/get-contributors.sh seedcase-project/template-workshop
18 changes: 18 additions & 0 deletions tools/get-contributors.sh
Original file line number Diff line number Diff line change
@@ -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