Skip to content

Commit 4e2f655

Browse files
authored
Improve reqs, docs and CI (#13)
* Updated pre-commit hooks * Updated pre commit hooks * isort before black * Updated python versions * Moved tests into the src * Added script for setting up project * Rename the import * Updated prints * Added more deps * Added _static * Moved custom.css * Rewrote the docs a bit * Updated the docs * Autosummary to gitignore * Added ruff to pre-commit * Added test_docs_job * Adde test_docs * isort,black --> ruff * Added rm * Test setup script * Fixes * Renaming * Separate tutorial and pytest * Fixed setup_project.sh * Test * Fixed setup_project.sh * Remove the test file in the script * Run everything relative to the script directory * Fixed docs build * Removed .github/workflows/test.yml * copy tutorials * Fix publishing to pypi * Formatting with prettier
1 parent 6bb5c50 commit 4e2f655

33 files changed

Lines changed: 607 additions & 257 deletions

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.ipynb filter=strip-notebook-output
1+
*.ipynb filter=strip-notebook-output
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Build Documentation"
2+
description: "Build Sphinx documentation"
3+
inputs:
4+
python-version:
5+
description: "Python version to use"
6+
required: false
7+
default: "3.10"
8+
treat-warnings-as-errors:
9+
description: "Treat warnings as errors (-W flag)"
10+
required: false
11+
default: "false"
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ inputs.python-version }}
19+
20+
- name: Install pandoc
21+
shell: bash
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y pandoc
25+
26+
- name: Install Python dependencies
27+
shell: bash
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install ".[docs]"
31+
32+
- name: Build Sphinx docs
33+
shell: bash
34+
run: |
35+
cd docs
36+
if [ "${{ inputs.treat-warnings-as-errors }}" = "true" ]; then
37+
sphinx-build -b html -W --keep-going source build/html
38+
else
39+
sphinx-build -b html source build/html
40+
fi
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Deploy docs to GitHub Pages
22

33
on:
44
push:
5-
branches: ["devel", "main"] # TODO: Set to main only after release
5+
branches: ["devel"]
66
workflow_dispatch:
77

88
permissions:
@@ -25,20 +25,11 @@ jobs:
2525
- name: Checkout
2626
uses: actions/checkout@v4
2727

28-
- name: Install pandoc
29-
run: |
30-
sudo apt-get update
31-
sudo apt-get install -y pandoc
32-
33-
- name: Install Python dependencies
34-
run: |
35-
python -m pip install --upgrade pip
36-
pip install ".[docs]"
37-
38-
- name: Build Sphinx docs
39-
run: |
40-
cd docs
41-
make html
28+
- name: Build documentation
29+
uses: ./.github/actions/build-docs
30+
with:
31+
python-version: "3.10"
32+
treat-warnings-as-errors: "false"
4233

4334
- name: Setup Pages
4435
uses: actions/configure-pages@v5
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ on:
88
jobs:
99
build-and-publish:
1010
runs-on: ubuntu-latest
11+
environment:
12+
name: pypi
13+
url: https://pypi.org/project/template-python/
14+
permissions:
15+
id-token: write
16+
contents: read
1117

1218
steps:
1319
- name: Checkout repository
@@ -21,15 +27,10 @@ jobs:
2127
- name: Install build tools
2228
run: |
2329
python -m pip install --upgrade pip
24-
pip install build twine
30+
pip install build
2531
2632
- name: Build the package
2733
run: python -m build
2834

29-
# Uncomment to publish on pypi
30-
#- name: Publish to PyPI
31-
# env:
32-
# TWINE_USERNAME: __token__ # Use API token
33-
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
34-
# run: twine upload dist/*
35-
35+
- name: Publish package distributions to PyPI
36+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/static_analysis.yml

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,32 @@ defaults:
1515
shell: bash
1616

1717
jobs:
18-
cloc:
18+
pre-commit:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Checkout the code
2222
uses: actions/checkout@v4
2323

24-
- name: Download and run cloc
25-
run: |
26-
curl -s https://raw.githubusercontent.com/AlDanial/cloc/master/cloc > cloc
27-
chmod +x cloc
28-
./cloc --version
29-
./cloc $(git ls-files)
30-
31-
black:
32-
runs-on: ubuntu-latest
33-
steps:
34-
- name: Checkout the code
35-
uses: actions/checkout@v4
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.10"
3628

37-
- name: Code formatting with black
38-
run: |
39-
pip install black "black[jupyter]"
40-
black --check src/
41-
black --check tutorials/
29+
- name: Run pre-commit
30+
uses: pre-commit/action@v3.0.1
4231

43-
isort:
32+
cloc:
4433
runs-on: ubuntu-latest
4534
steps:
4635
- name: Checkout the code
4736
uses: actions/checkout@v4
4837

49-
- name: Code formatting with isort
38+
- name: Download and run cloc
5039
run: |
51-
pip install isort
52-
isort --check src/
53-
isort --check tutorials/
40+
curl -s https://raw.githubusercontent.com/AlDanial/cloc/master/cloc > cloc
41+
chmod +x cloc
42+
./cloc --version
43+
./cloc $(git ls-files)
5444
5545
mypy:
5646
runs-on: ubuntu-latest
@@ -59,43 +49,12 @@ jobs:
5949
- name: Checkout the code
6050
uses: actions/checkout@v4
6151

52+
- name: Set up Python
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: "3.10"
56+
6257
- name: Type checking with mypy
6358
run: |
6459
pip install mypy
6560
mypy src/ || true
66-
67-
prospector:
68-
runs-on: ubuntu-latest
69-
continue-on-error: true
70-
steps:
71-
- name: Checkout the code
72-
uses: actions/checkout@v4
73-
74-
- name: Code analysis with prospector
75-
run: |
76-
pip install prospector
77-
prospector src/ || true
78-
79-
ruff:
80-
runs-on: ubuntu-latest
81-
continue-on-error: true
82-
steps:
83-
- name: Checkout the code
84-
uses: actions/checkout@v4
85-
86-
- name: Linting with ruff
87-
run: |
88-
pip install ruff
89-
ruff check src/ || true
90-
91-
pylint:
92-
runs-on: ubuntu-latest
93-
continue-on-error: true
94-
steps:
95-
- name: Checkout the code
96-
uses: actions/checkout@v4
97-
98-
- name: Linting with pylint
99-
run: |
100-
pip install pylint
101-
pylint src/ || true

.github/workflows/test_docs.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test Documentation Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- devel
8+
pull_request:
9+
branches:
10+
- main
11+
- devel
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
jobs:
18+
test-docs:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Build documentation
25+
uses: ./.github/actions/build-docs
26+
with:
27+
python-version: "3.10"
28+
treat-warnings-as-errors: "true"
29+
30+
- name: Upload docs artifact
31+
uses: actions/upload-artifact@v4
32+
if: always()
33+
with:
34+
name: documentation
35+
path: docs/build/html/
36+
retention-days: 7

.github/workflows/test_pytest.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test Pytest
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- devel
8+
pull_request:
9+
branches:
10+
- main
11+
- devel
12+
13+
jobs:
14+
pytest:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.10"
25+
26+
- name: Cache pip
27+
uses: actions/cache@v4
28+
with:
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
34+
- name: Install project
35+
run: |
36+
pip install --upgrade pip
37+
pip install ".[test]"
38+
39+
- name: Run tests
40+
run: |
41+
pytest .
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Test Setup Script
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- devel
8+
pull_request:
9+
branches:
10+
- main
11+
- devel
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
jobs:
18+
test-setup-script:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.10"
28+
29+
- name: Run setup script
30+
run: |
31+
bash setup_project.sh my-test-app
32+
33+
- name: Verify changes
34+
run: |
35+
# Check that src/app was moved to src/my_test_app
36+
if [ ! -d "src/my_test_app" ]; then
37+
echo "Error: src/my_test_app does not exist"
38+
exit 1
39+
fi
40+
41+
# Check that src/app no longer exists
42+
if [ -d "src/app" ]; then
43+
echo "Error: src/app still exists"
44+
exit 1
45+
fi
46+
47+
# Check that template-python was replaced in pyproject.toml
48+
if grep -q "template-python" pyproject.toml; then
49+
echo "Error: 'template-python' still found in pyproject.toml"
50+
exit 1
51+
fi
52+
53+
if ! grep -q "my-test-app" pyproject.toml; then
54+
echo "Error: 'my-test-app' not found in pyproject.toml"
55+
exit 1
56+
fi
57+
58+
echo "✓ All checks passed!"
59+
60+
- name: Install project with new name
61+
run: |
62+
pip install --upgrade pip
63+
pip install -e .
64+
65+
- name: Test renamed command works
66+
run: |
67+
my-test-app

0 commit comments

Comments
 (0)