Skip to content

Commit afbbb98

Browse files
committed
local pre-commit hooks
1 parent 102b125 commit afbbb98

File tree

6 files changed

+174
-26
lines changed

6 files changed

+174
-26
lines changed

.github/workflows/pre-commit.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v3
12-
- uses: actions/setup-python@v4
12+
13+
- uses: astral-sh/setup-uv@884ad927a57e558e7a70b92f2bccf9198a4be546 # v6
14+
with:
15+
version: '0.8.2'
16+
# we just cache the venv-dir directly in action-setup-venv
17+
enable-cache: false
18+
19+
- uses: getsentry/[email protected]
1320
with:
14-
python-version: '3.11'
21+
cache-dependency-path: uv.lock
22+
install-cmd: uv sync --frozen --active
23+
1524
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,42 @@ repos:
1212
hooks:
1313
- id: reorder-python-imports
1414
args: [--py311-plus, --add-import, 'from __future__ import annotations']
15-
- repo: https://github.com/psf/black
16-
rev: 24.1.1
17-
hooks:
18-
- id: black
19-
- repo: https://github.com/asottile/pyupgrade
20-
rev: v3.15.0
21-
hooks:
22-
- id: pyupgrade
23-
args: [--py311-plus]
24-
- repo: https://github.com/PyCQA/flake8
25-
rev: 7.0.0
26-
hooks:
27-
- id: flake8
28-
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.8.0
30-
hooks:
31-
- id: mypy
3215
- repo: local
3316
hooks:
3417
- id: format-packages-ini
3518
name: format packages.ini
3619
language: python
37-
entry: python -m format_ini
20+
entry: .venv/bin/python -m format_ini
3821
files: ^packages\.ini$
39-
additional_dependencies: [packaging==21.3]
22+
23+
# Configuration for black exists in pyproject.toml,
24+
# but we let pre-commit take care of the file filtering.
25+
- id: black
26+
name: black
27+
entry: .venv/bin/black
28+
language: system
29+
types_or: [python, pyi]
30+
require_serial: true
31+
32+
# Configuration for flake8 exists in setup.cfg,
33+
# but we let pre-commit take care of the file filtering.
34+
- id: flake8
35+
name: flake8
36+
entry: .venv/bin/flake8
37+
language: system
38+
types: [python]
39+
require_serial: true
40+
41+
- id: pyupgrade
42+
name: pyupgrade
43+
entry: .venv/bin/pyupgrade
44+
language: system
45+
types: [python]
46+
args: [--py311-plus]
47+
48+
- id: mypy
49+
name: mypy
50+
entry: .venv/bin/mypy
51+
language: system
52+
types: [python]
53+
require_serial: true

build.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _brew_paths(*pkgs: str) -> list[str]:
146146

147147

148148
@contextlib.contextmanager
149-
def _brew_install(packages: tuple[str, ...]) -> Generator[None, None, None]:
149+
def _brew_install(packages: tuple[str, ...]) -> Generator[None]:
150150
installed_before = _darwin_installed_packages()
151151

152152
subprocess.check_call(
@@ -180,7 +180,7 @@ def _paths(*parts: str) -> list[str]:
180180

181181

182182
@contextlib.contextmanager
183-
def _darwin_install(package: Package) -> Generator[None, None, None]:
183+
def _darwin_install(package: Package) -> Generator[None]:
184184
with contextlib.ExitStack() as ctx:
185185
if package.brew_requires:
186186
ctx.enter_context(_brew_install(package.brew_requires))
@@ -252,7 +252,7 @@ def _linux_installed_packages() -> frozenset[str]:
252252

253253

254254
@contextlib.contextmanager
255-
def _apt_install(packages: tuple[str, ...]) -> Generator[None, None, None]:
255+
def _apt_install(packages: tuple[str, ...]) -> Generator[None]:
256256
_apt_update()
257257

258258
installed_before = _linux_installed_packages()
@@ -280,7 +280,7 @@ def _apt_install(packages: tuple[str, ...]) -> Generator[None, None, None]:
280280

281281

282282
@contextlib.contextmanager
283-
def _linux_install(package: Package) -> Generator[None, None, None]:
283+
def _linux_install(package: Package) -> Generator[None]:
284284
with contextlib.ExitStack() as ctx:
285285
if package.apt_requires:
286286
ctx.enter_context(_apt_install(package.apt_requires))
@@ -446,7 +446,7 @@ def _join_env(
446446
@contextlib.contextmanager
447447
def _prebuild(
448448
package: Package, tmpdir: str, *, env: MutableMapping[str, str] | None = None
449-
) -> Generator[None, None, None]:
449+
) -> Generator[None]:
450450
if env is None:
451451
env = os.environ
452452

devenv/sync.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ def main(context: dict[str, str]) -> int:
2020
print("syncing .venv ...")
2121
proc.run(("uv", "sync", "--frozen", "--quiet"))
2222

23+
print("installing pre-commit hooks ...")
24+
proc.run((f"{reporoot}/.venv/bin/pre-commit", "install", "--install-hooks"))
25+
2326
return 0

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ version = "0.0.0"
99
# and run pytest on 3 different python versions in ci by swapping out .python-version.
1010
# Tox remains the most ergonomic solution to test on multiple pythons.
1111
dev = [
12+
"black>=22.10.0",
13+
"flake8>=7.3.0",
14+
"mypy>=1.18.2",
1215
"packaging==21.3",
1316
"pre-commit==4.2.0",
17+
"pyupgrade>=3.19.1",
1418
"sentry-devenv>=1.25.0",
1519
"tox==3.25.1",
1620
]

uv.lock

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)