Skip to content

Commit 096781a

Browse files
authored
build: 🔧 update config for non-template package (#116)
1 parent c9c7dd1 commit 096781a

File tree

9 files changed

+99
-113
lines changed

9 files changed

+99
-113
lines changed

.github/workflows/build-website.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions: read-all
1010

1111
jobs:
1212
build-website:
13-
uses: seedcase-project/.github/.github/workflows/reusable-build-docs-with-python.yml@main
13+
uses: seedcase-project/.github/.github/workflows/reusable-build-docs.yml@main
1414
secrets:
1515
netlify-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
1616
# This is to allow using `gh` CLI

.gitignore

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,6 @@ venv
2626
__pycache__/
2727
*.py[cod]
2828

29-
# Python packaging and distribution
30-
.Python
31-
build/
32-
develop-eggs/
33-
dist/
34-
downloads/
35-
eggs/
36-
.eggs/
37-
lib/
38-
lib64/
39-
parts/
40-
sdist/
41-
var/
42-
wheels/
43-
share/python-wheels/
44-
*.egg-info/
45-
.installed.cfg
46-
*.egg
47-
MANIFEST
48-
49-
# Python testing and code coverage
50-
htmlcov/
51-
.tox/
52-
.nox/
53-
.coverage
54-
.coverage.*
55-
coverage.*
56-
.cache
57-
nosetests.xml
58-
*.cover
59-
*.py,cover
60-
.hypothesis/
61-
.pytest_cache/
62-
cover/
63-
6429
# MacOS
6530
.DS_Store
6631

.vscode/extensions.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
"felipecaputo.git-project-manager",
88
"GitHub.vscode-pull-request-github",
99
"ms-python.python",
10-
"ms-python.vscode-pylance",
11-
"matangover.mypy",
12-
"njpwerner.autodocstring",
1310
"quarto.quarto",
1411
"ms-toolsai.jupyter",
1512
"vivaxy.vscode-conventional-commits",
16-
"charliermarsh.ruff",
1713
"pshaddel.conventional-branch",
1814
"tekumara.typos-vscode",
1915
"EditorConfig.EditorConfig"

.vscode/settings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
"[quarto][qmd]": {
2727
"editor.formatOnSave": false
2828
},
29-
"[python]": {
30-
"editor.defaultFormatter": "charliermarsh.ruff"
31-
},
3229
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
3330
"python.languageServer": "Pylance",
3431
"files.insertFinalNewline": true,
35-
"python.testing.pytestEnabled": true,
36-
"python.testing.pytestPath": "${workspaceFolder}/.venv/bin/pytest",
37-
"mypy.runUsingActiveInterpreter": true,
32+
"files.associations": {
33+
"*.yml.jinja": "jinja-yaml",
34+
"*.cff.jinja": "jinja-yaml",
35+
"*.toml.jinja": "jinja-toml",
36+
"*.qmd.jinja": "jinja-md"
37+
},
3838
}

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
2+
13
# Template for Seedcase Python packages
24

3-
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:
5+
This repository contains a template for setting up new Python package
6+
projects in Seedcase. The first step is to create a new repository using
7+
this template. This can easily be done by clicking the “Use this
8+
template” button on the repository page or by using the GitHub CLI:
49

510
``` bash
611
# NAME is the name to give the new repository
@@ -9,11 +14,14 @@ gh repo create NAME --template seedcase-project/template-python-project
914

1015
## Setting things up after cloning
1116

12-
Search for `NAME` and `REPO` and replace them with the name of your project and the repository name. Then look for any `TODO` items.
17+
Search for `NAME` and `REPO` and replace them with the name of your
18+
project and the repository name. Then look for any `TODO` items.
1319

1420
## Setting things up
1521

16-
Use the commands found in [`spaid`](https://github.com/seedcase-project/spaid) repo to run the next setup steps.
22+
Use the commands found in
23+
[`spaid`](https://github.com/seedcase-project/spaid) repo to run the
24+
next setup steps.
1725

1826
Need to install these packages after:
1927

README.qmd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Template for Seedcase Python packages
2+
3+
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:
4+
5+
``` bash
6+
# NAME is the name to give the new repository
7+
gh repo create NAME --template seedcase-project/template-python-project
8+
```
9+
10+
## Setting things up after cloning
11+
12+
Search for `NAME` and `REPO` and replace them with the name of your project and the repository name. Then look for any `TODO` items.
13+
14+
## Setting things up
15+
16+
Use the commands found in [`spaid`](https://github.com/seedcase-project/spaid) repo to run the next setup steps.
17+
18+
Need to install these packages after:
19+
20+
``` bash
21+
uv add --dev pre-commit ruff typos pytest bandit commitizen \
22+
genbadge jupyter pytest-cov quartodoc
23+
```

_publish.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
- source: project
22
netlify:
3-
# TODO: Include correct ID
4-
- id: ""
5-
url: "https://NAME-seedcase-project.netlify.app"
3+
- id: "8775b18b-3a1a-4dfc-b6c7-a1ef7205d30f"
4+
url: "https://seedcase-template-python-package.netlify.app"

justfile

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@_default:
22
just --list --unsorted
33

4+
@_checks: check-spelling check-commits
5+
@_builds: build-contributors build-website build-readme
6+
47
# Run all build-related recipes in the justfile
5-
run-all: install-deps format-python check-python check-unused test-python check-security check-spelling check-commits build-website
8+
run-all: update-quarto-theme update-template _checks test _builds
69

710
# Install the pre-commit hooks
811
install-precommit:
@@ -13,78 +16,52 @@ install-precommit:
1316
# Update versions of pre-commit hooks
1417
uvx pre-commit autoupdate
1518

16-
# Install Python package dependencies
17-
install-deps:
18-
uv sync --all-extras --dev
19-
20-
# Run the Python tests
21-
test-python:
22-
uv run pytest
23-
# Make the badge from the coverage report
24-
uv run genbadge coverage \
25-
-i coverage.xml \
26-
-o htmlcov/coverage.svg
27-
28-
# Check Python code for any errors that need manual attention
29-
check-python:
30-
# Check formatting
31-
uv run ruff check .
32-
# Check types
33-
uv run mypy .
19+
# Update the Quarto seedcase-theme extension
20+
update-quarto-theme:
21+
quarto add seedcase-project/seedcase-theme --no-prompt
3422

35-
# Reformat Python code to match coding style and general structure
36-
format-python:
37-
uv run ruff check --fix .
38-
uv run ruff format .
23+
# Update files in the template from the copier parent folder
24+
update-template:
25+
cp .cz.toml .pre-commit-config.yaml .typos.toml .editorconfig template/
26+
mkdir -p template/tools
27+
cp tools/get-contributors.sh template/tools/
28+
cp .github/pull_request_template.md template/.github/
29+
cp .github/workflows/build-website.yml .github/workflows/dependency-review.yml template/.github/workflows/
3930

40-
# Build the documentation website using Quarto
41-
build-website:
42-
# To let Quarto know where python is.
43-
export QUARTO_PYTHON=.venv/bin/python3
44-
# Delete any previously built files from quartodoc.
45-
# -f is to not give an error if the files don't exist yet.
46-
rm -f docs/reference/*.qmd
47-
uv run quartodoc build
48-
uv run quarto render --execute
49-
50-
# Run checks on commits with non-main branches
31+
# Check the commit messages on the current branch that are not on the main branch
5132
check-commits:
5233
#!/bin/zsh
5334
branch_name=$(git rev-parse --abbrev-ref HEAD)
5435
number_of_commits=$(git rev-list --count HEAD ^main)
5536
if [[ ${branch_name} != "main" && ${number_of_commits} -gt 0 ]]
5637
then
57-
uv run cz check --rev-range main..HEAD
38+
uvx --from commitizen cz check --rev-range main..HEAD
5839
else
59-
echo "Can't either be on ${branch_name} or have more than ${number_of_commits}."
40+
echo "On `main` or current branch doesn't have any commits."
6041
fi
6142

62-
# Run basic security checks on the package
63-
check-security:
64-
uv run bandit -r src/
65-
6643
# Check for spelling errors in files
6744
check-spelling:
68-
uv run typos
45+
uvx typos
46+
47+
# Test and check that a Python package can be created from the template
48+
# TODO: add test for copier
49+
test:
50+
echo "copier test"
51+
52+
# Clean up any leftover and temporary build files
53+
cleanup:
54+
#!/bin/zsh
55+
rm -rf _temp
56+
57+
# Build the website using Quarto
58+
build-website:
59+
uvx --from quarto quarto render
6960

70-
# Build the documentation as PDF using Quarto
71-
build-pdf:
72-
# To let Quarto know where python is.
73-
export QUARTO_PYTHON=.venv/bin/python3
74-
uv run quarto install tinytex
75-
# For generating images from Mermaid diagrams
76-
uv run quarto install chromium
77-
uv run quarto render --profile pdf --to pdf
78-
find docs -name "mermaid-figure-*.png" -delete
61+
# Re-build the README file from the Quarto version
62+
build-readme:
63+
uvx --from quarto quarto render README.qmd --to gfm
7964

80-
# Check for unused code in the package and its tests
81-
check-unused:
82-
# exit code=0: No unused code was found
83-
# exit code=3: Unused code was found
84-
# Three confidence values:
85-
# - 100 %: function/method/class argument, unreachable code
86-
# - 90 %: import
87-
# - 60 %: attribute, class, function, method, property, variable
88-
# There are some things should be ignored though, with the allowlist.
89-
# Create an allowlist with `vulture --make-allowlist`
90-
uv run vulture src/ tests/ **/vulture-allowlist.py
65+
# Generate a Quarto include file with the contributors
66+
build-contributors:
67+
sh ./tools/get-contributors.sh seedcase-project/template-workshop

tools/get-contributors.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# Get a list of contributors to this repository and save it to
4+
# _contributors.qmd.tmp file. It also:
5+
#
6+
# - Formats users into Markdown links to their GitHub profiles.
7+
# - Removes any usernames with the word "bot" in them.
8+
# - Removes the trailing comma from the list.
9+
repo_spec=${1}
10+
echo "These are the people who have contributed by submitting changes through pull requests :tada:\n\n" > _contributors.qmd.tmp
11+
gh api \
12+
-H "Accept: application/vnd.github+json" \
13+
-H "X-GitHub-Api-Version: 2022-11-28" \
14+
/repos/$repo_spec/contributors \
15+
--template '{{range .}} [\@{{.login}}]({{.html_url}}){{"\n"}}{{end}}' | \
16+
grep -v "\[bot\]" | \
17+
tr '\n' ', ' | \
18+
sed -e 's/,$//' >> _contributors.qmd.tmp

0 commit comments

Comments
 (0)