Skip to content

Commit aff7f2d

Browse files
committed
Update core project
1 parent 98331c5 commit aff7f2d

File tree

8 files changed

+1421
-148
lines changed

8 files changed

+1421
-148
lines changed

.github/workflows/test-lint.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Test and lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
id: setup-python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.13"
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v6
25+
26+
- name: Load cache
27+
id: cached-poetry-dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: .venv
31+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/uv.lock') }}
32+
33+
- name: Install dependencies if cache does not exist
34+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
35+
run: uv sync --locked --all-extras --dev
36+
37+
- name: Check dependencies
38+
run: make check-dependencies
39+
40+
- name: Check codestyle
41+
run: make check-codestyle
42+
43+
- name: ruff
44+
run: make check-ruff-github
45+
46+
- name: mypy
47+
run: make check-mypy
48+
49+
test:
50+
runs-on: ubuntu-latest
51+
permissions: write-all
52+
steps:
53+
54+
- name: Check out repository
55+
uses: actions/checkout@v4
56+
57+
- name: Set up Python
58+
id: setup-python
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: "3.13"
62+
63+
- name: Install uv
64+
uses: astral-sh/setup-uv@v6
65+
66+
- name: Load cache
67+
id: cached-poetry-dependencies
68+
uses: actions/cache@v4
69+
with:
70+
path: .venv
71+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/uv.lock') }}
72+
73+
- name: Install dependencies if cache does not exist
74+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
75+
run: uv sync --locked --all-extras --dev
76+
77+
- name: Run tests
78+
run: make test
79+
80+
- name: Code Coverage Summary Report
81+
uses: irongut/[email protected]
82+
with:
83+
filename: reports/coverage.xml
84+
badge: true
85+
format: 'markdown'
86+
output: 'both'
87+
88+
- name: Add Coverage PR Comment
89+
uses: marocchino/sticky-pull-request-comment@v2
90+
if: github.event_name == 'pull_request'
91+
with:
92+
recreate: true
93+
path: code-coverage-results.md
94+
95+
- name: Add Coverage Report to Job Summary
96+
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

Makefile

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,127 @@
11
#* Variables
2-
SHELL := /usr/bin/env bash
2+
SHELL := /usr/bin/env bash -o pipefail
33
PYTHON := python3
4-
PYTHONPATH := `pwd`
54

6-
#* Poetry
7-
.PHONY: poetry-download
8-
poetry-download:
9-
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.5 $(PYTHON) -
5+
#* Directories with source code
6+
CODE = hooks tests
7+
TESTS = tests
108

11-
.PHONY: poetry-remove
12-
poetry-remove:
13-
curl -sSL https://install.python-poetry.org | $(PYTHON) - --uninstall
9+
#* uv package manager
10+
.PHONY: uv-install
11+
uv-install:
12+
curl -LsSf https://astral.sh/uv/install.sh | sh
1413

1514
#* Installation
1615
.PHONY: install
1716
install:
18-
poetry lock -n && poetry export --without-hashes > requirements.txt
19-
poetry install -n
20-
poetry run mypy --install-types --non-interactive hooks tests
17+
uv sync
2118

2219
.PHONY: pre-commit-install
2320
pre-commit-install:
24-
poetry run pre-commit install
21+
uv run pre-commit install
2522

2623
#* Formatters
2724
.PHONY: codestyle
2825
codestyle:
29-
poetry run pyupgrade --exit-zero-even-if-changed --py37-plus **/*.py
30-
poetry run isort --settings-path pyproject.toml hooks tests
31-
poetry run black --config pyproject.toml hooks tests
26+
uv run ruff format $(CODE)
27+
uv run ruff check $(CODE) --fix-only
3228

33-
.PHONY: formatting
34-
formatting: codestyle
29+
.PHONY: format
30+
format: codestyle
3531

36-
#* Linting
32+
#* Test
3733
.PHONY: test
3834
test:
39-
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=hooks tests/
35+
uv run pytest
36+
uv run coverage xml
37+
38+
# Validate dependencies
39+
.PHONY: check-uv
40+
check-uv:
41+
uv lock --check
42+
43+
.PHONY: check-deptry
44+
check-deptry:
45+
uv run deptry .
46+
47+
.PHONY: check-dependencies
48+
check-dependencies: check-uv check-deptry
49+
50+
#* Static linters
51+
52+
.PHONY: check-ruff
53+
check-ruff:
54+
uv run ruff check $(CODE) --no-fix
4055

4156
.PHONY: check-codestyle
4257
check-codestyle:
43-
poetry run isort --diff --check-only --settings-path pyproject.toml hooks tests
44-
poetry run black --diff --check --config pyproject.toml hooks tests
45-
poetry run darglint --verbosity 2 hooks tests
58+
uv run ruff format $(CODE) --check
59+
60+
61+
.PHONY: check-ruff-github
62+
check-ruff-github:
63+
uv run ruff check $(CODE) --no-fix --output-format=github
4664

47-
.PHONY: mypy
48-
mypy:
49-
poetry run mypy --config-file pyproject.toml hooks tests
65+
66+
.PHONY: check-mypy
67+
check-mypy:
68+
uv run mypy --install-types --non-interactive --config-file pyproject.toml $(CODE)
69+
70+
.PHONY: static-lint
71+
static-lint: check-ruff check-mypy
72+
73+
#* Check safety
5074

5175
.PHONY: check-safety
5276
check-safety:
53-
poetry check
54-
poetry run safety check --full-report
55-
poetry run bandit -ll --recursive hooks
77+
uv run safety check --full-report
5678

5779
.PHONY: lint
58-
lint: test check-codestyle mypy check-safety
80+
lint: check-dependencies check-codestyle static-lint
5981

60-
.PHONY: update-dev-deps
61-
update-dev-deps:
62-
poetry add -D black@latest bandit@latest darglint@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest safety@latest coverage@latest pytest-html@latest pytest-cov@latest
82+
# Currently not supported in uv: https://github.com/astral-sh/uv/issues/6794
83+
#.PHONY: update-dev-deps
84+
#update-dev-deps:
85+
# poetry add -G dev mypy@latest pre-commit@latest pytest@latest deptry@latest \
86+
# coverage@latest safety@latest typeguard@latest ruff@latest
87+
88+
.PHONY: update
89+
update:
90+
uv lock --upgrade
6391

6492
#* Cleaning
6593
.PHONY: pycache-remove
6694
pycache-remove:
67-
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
95+
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf || true
6896

6997
.PHONY: dsstore-remove
7098
dsstore-remove:
71-
find . | grep -E ".DS_Store" | xargs rm -rf
99+
find . | grep -E ".DS_Store" | xargs rm -rf || true
72100

73101
.PHONY: mypycache-remove
74102
mypycache-remove:
75-
find . | grep -E ".mypy_cache" | xargs rm -rf
103+
find . | grep -E ".mypy_cache" | xargs rm -rf || true
76104

77105
.PHONY: ipynbcheckpoints-remove
78106
ipynbcheckpoints-remove:
79-
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
107+
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf || true
80108

81109
.PHONY: pytestcache-remove
82110
pytestcache-remove:
83-
find . | grep -E ".pytest_cache" | xargs rm -rf
111+
find . | grep -E ".pytest_cache" | xargs rm -rf || true
112+
113+
.PHONY: ruffcache-remove
114+
ruffcache-remove:
115+
find . | grep -E ".ruff_cache" | xargs rm -rf || true
84116

85117
.PHONY: build-remove
86118
build-remove:
87119
rm -rf build/
88120

121+
.PHONY: reports-remove
122+
reports-remove:
123+
rm -rf reports/
124+
89125
.PHONY: cleanup
90-
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove
126+
cleanup: pycache-remove dsstore-remove mypycache-remove ruffcache-remove \
127+
ipynbcheckpoints-remove pytestcache-remove reports-remove

hooks/__init__.py

Whitespace-only changes.

hooks/post_gen_project.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""This module is called after project is created."""
2+
23
import textwrap
4+
35
from pathlib import Path
46

57
# Project root directory
@@ -51,7 +53,7 @@ def print_further_instructions(project_name: str, git_repo_url: str) -> None:
5153
print(textwrap.dedent(message))
5254

5355

54-
def rm_tree(pth: Path):
56+
def rm_tree(pth: Path) -> None:
5557
for child in pth.iterdir():
5658
if child.is_file():
5759
child.unlink()
@@ -60,10 +62,7 @@ def rm_tree(pth: Path):
6062
pth.rmdir()
6163

6264

63-
def remove_unrelated_ci_configuration(
64-
project_directory: Path,
65-
git_platform: str,
66-
) -> None:
65+
def remove_unrelated_ci_configuration(project_directory: Path, git_platform: str) -> None:
6766
if git_platform == "github":
6867
(project_directory / ".gitlab-ci.yml").unlink()
6968
elif git_platform == "gitlab":
@@ -75,8 +74,7 @@ def remove_unrelated_ci_configuration(
7574
def main() -> None:
7675
print_further_instructions(project_name=PROJECT_NAME, git_repo_url=GIT_REPO_URL)
7776
remove_unrelated_ci_configuration(
78-
project_directory=PROJECT_DIRECTORY,
79-
git_platform=GIT_PLATFORM,
77+
project_directory=PROJECT_DIRECTORY, git_platform=GIT_PLATFORM
8078
)
8179

8280

0 commit comments

Comments
 (0)