Skip to content

Commit e6d7c0f

Browse files
authored
Update stuff with latest best practices (#2)
* new version * add pydantic * use mypy
1 parent 4686795 commit e6d7c0f

File tree

15 files changed

+1302
-129
lines changed

15 files changed

+1302
-129
lines changed

.github/workflows/docs.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: website
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- docs/*
7+
env:
8+
COLUMNS: 150
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 30
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: checkout gh-pages
18+
uses: actions/checkout@v4
19+
with:
20+
ref: gh-pages
21+
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.12'
25+
26+
- name: install
27+
run: pip install uv
28+
29+
- name: checkout current branch
30+
uses: actions/checkout@v4
31+
32+
- name: Set git credentials
33+
run: |
34+
git config --global user.name "${{ github.actor }}"
35+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
36+
37+
- run: uv run --extra doc mike deploy -b gh-pages dev --push
38+
if: github.ref == 'refs/heads/main'
39+
40+
- if: startsWith(github.ref, 'refs/heads/docs')
41+
id: check-version
42+
uses: samuelcolvin/check-python-version@v4.1
43+
with:
44+
version_file_path: 'src/your_package_name/__about__.py'
45+
skip_env_check: true
46+
47+
- run: uv run --extra doc mike deploy -b gh-pages ${{ steps.check-version.outputs.VERSION }} latest --update-aliases --push
48+
if: startsWith(github.ref, 'refs/heads/docs') && !fromJSON(steps.check-version.outputs.IS_PRERELEASE)
49+
env:
50+
VERSION: v${{ steps.check-version.outputs.VERSION }}

.github/workflows/mypy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Mypy
2+
on: [push]
3+
4+
jobs:
5+
Static-Type-Checking:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
max-parallel: 5
9+
matrix:
10+
python-version: ["3.10", "3.11", "3.12"]
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install system packages
19+
run: sudo apt-get install -y portaudio19-dev
20+
- name: Display Python version
21+
run: python -c "import sys; print(sys.version)"
22+
- name: Install dependencies
23+
run: |
24+
curl -LsSf https://astral.sh/uv/install.sh | sh
25+
- name: Type-checking package with mypy
26+
run: |
27+
uv run --all-extras mypy --strict .

.github/workflows/pr-checks.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- name: Set up Python 3.11
1414
uses: actions/setup-python@v4
1515
with:

.github/workflows/tests.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ repos:
1111
hooks:
1212
- id: prettier
1313
types_or: [html]
14-
- repo: https://github.com/psf/black
15-
rev: 22.12.0
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
# Ruff version.
16+
rev: v0.3.5
1617
hooks:
17-
- id: black
18-
args: [--line-length=79]
19-
- repo: https://github.com/pycqa/isort
20-
rev: 5.12.0
21-
hooks:
22-
- id: isort
23-
args: ["--profile", "black", --line-length=72]
18+
# Run the linter.
19+
- id: ruff
20+
types_or: [ python, pyi, jupyter ]
21+
args: [ --fix ]
22+
# Run the formatter.
23+
- id: ruff-format
24+
types_or: [ python, pyi, jupyter ]
2425
- repo: https://github.com/kynan/nbstripout
2526
rev: 0.6.0
2627
hooks:

docs/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# What is this?
2+
3+
This is Python project template that I use for my projects.
4+
5+
## Features
6+
7+
1. `pyproject.toml` for managing dependencies and project metadata.
8+
2. `mypy` for static type checking.
9+
3. `pre-commit` for running code checks before committing.
10+
4. `pytest` for running tests.
11+
5. `mkdocs` for generating documentation.

mkdocs.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
site_name: Your Package Name
2+
site_description: Your package description
3+
strict: true
4+
site_url: https://python_template.zhuhao.me
5+
repo_url: https://github.com/ProKil/python_project_template
6+
repo_name: Python Project Template
7+
8+
theme:
9+
name: "material"
10+
icon:
11+
repo: fontawesome/brands/github
12+
palette:
13+
- media: "(prefers-color-scheme)"
14+
scheme: default
15+
primary: deep purple
16+
accent: amber
17+
toggle:
18+
icon: material/lightbulb
19+
name: "Switch to light mode"
20+
- media: "(prefers-color-scheme: light)"
21+
scheme: default
22+
primary: deep purple
23+
accent: amber
24+
toggle:
25+
icon: material/lightbulb-outline
26+
name: "Switch to dark mode"
27+
- media: "(prefers-color-scheme: dark)"
28+
scheme: slate
29+
primary: deep purple
30+
accent: amber
31+
toggle:
32+
icon: material/lightbulb-auto-outline
33+
name: "Switch to system preference"
34+
features:
35+
- content.tabs.link
36+
- content.code.annotate
37+
- content.code.copy
38+
- announce.dismiss
39+
- navigation.tabs
40+
- navigation.instant
41+
- navigation.instant.prefetch
42+
- navigation.instant.preview
43+
- navigation.instant.progress
44+
- navigation.path
45+
- navigation.sections
46+
- navigation.top
47+
- navigation.tracking
48+
- search.suggest
49+
- toc.follow
50+
51+
extra:
52+
version:
53+
provider: mike
54+
analytics:
55+
feedback:
56+
title: Was this page helpful?
57+
ratings:
58+
- icon: material/thumb-up-outline
59+
name: This page was helpful
60+
data: 1
61+
note: >-
62+
Thanks for your feedback!
63+
- icon: material/thumb-down-outline
64+
name: This page could be improved
65+
data: 0
66+
note: >-
67+
Thanks for your feedback!
68+
nav:
69+
- Get Started:
70+
- What is this: index.md
71+
72+
plugins:
73+
- social
74+
- search
75+
- mike:
76+
alias_type: symlink
77+
canonical_version: latest
78+
- exclude:
79+
glob:
80+
- theme/announce.html
81+
- plugins/*
82+
- __pycache__/*
83+
- mkdocstrings:
84+
handlers:
85+
python:
86+
paths: [.]
87+
options:
88+
members_order: source
89+
separate_signature: true
90+
filters: ["!^_"]
91+
docstring_options:
92+
ignore_init_summary: true
93+
merge_init_into_class: true
94+
show_signature_annotations: true
95+
signature_crossrefs: true
96+
extensions:
97+
- docs/plugins/griffe_doclinks.py
98+
import:
99+
- url: https://docs.python.org/3/objects.inv
100+
domains: [py, std]

pyproject.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[project]
2+
name = "your-package-name"
3+
description = "Your package description"
4+
readme = "README.md"
5+
requires-python = ">=3.10"
6+
dependencies = [
7+
"pydantic",
8+
]
9+
dynamic = ["version"]
10+
11+
[tool.hatch]
12+
version = {path = "src/your_package_name/__about__.py"}
13+
14+
[project.optional-dependencies]
15+
typing = [
16+
"mypy",
17+
]
18+
doc = [
19+
"mike",
20+
"mkdocs-exclude",
21+
"mkdocs-material[imaging]",
22+
"mkdocstrings[python]",
23+
"mkdocs-material[doc]>=9.5.43",
24+
]
25+
26+
[build-system]
27+
requires = ["hatchling"]
28+
build-backend = "hatchling.build"
29+
30+
[tool.uv]
31+
dev-dependencies = [
32+
"mypy",
33+
"pytest"
34+
]
35+
36+
[tool.mypy]
37+
plugins = [
38+
"pydantic.mypy",
39+
"pydantic.v1.mypy",
40+
]
41+
exclude = [
42+
"docs"
43+
]

setup.cfg

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)