Skip to content

Commit 723bfbd

Browse files
authored
Use ruff, wps@1.1, pre-commit CI (#532)
1 parent 82c9a19 commit 723bfbd

28 files changed

+1976
-1840
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ updates:
66
interval: daily
77
time: "02:00"
88
open-pull-requests-limit: 10
9+
910
- package-ecosystem: pip
1011
directory: "/{{cookiecutter.project_name}}"
1112
schedule:
1213
interval: daily
1314
time: "02:00"
1415
open-pull-requests-limit: 10
15-
- package-ecosystem: pip
16-
directory: "/{{cookiecutter.project_name}}/docs"
17-
schedule:
18-
interval: daily
19-
time: "02:00"
20-
open-pull-requests-limit: 10
2116

2217
- package-ecosystem: github-actions
2318
directory: "/"

.github/workflows/test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: ['3.9', '3.10', '3.11', '3.12']
23+
python-version: ['3.10', '3.11', '3.12', '3.13']
2424

2525
steps:
2626
- uses: actions/checkout@v4
27+
with:
28+
persist-credentials: false
29+
2730
- name: Set up Python ${{ matrix.python-version }}
2831
uses: actions/setup-python@v5
2932
with:
@@ -34,7 +37,7 @@ jobs:
3437
curl -sSL "https://install.python-poetry.org" | python
3538
3639
# Adding `poetry` to `$PATH`:
37-
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
40+
echo "$HOME/.poetry/bin" >> "$GITHUB_PATH"
3841
3942
- name: Install dependencies
4043
run: |
@@ -44,8 +47,14 @@ jobs:
4447
4548
- name: Run checks
4649
run: |
50+
poetry run ruff check --exit-non-zero-on-fix --diff
51+
poetry run ruff format --check --diff
4752
poetry run flake8 .
53+
poetry run mypy .
4854
poetry run pytest
4955
poetry run poetry check
5056
poetry run pip check
57+
58+
- name: Run integration test
59+
run: |
5160
poetry run sh tests/test_integration.sh

.github/zizmor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rules:
2+
unpinned-uses:
3+
config:
4+
policies:
5+
"*": ref-pin

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,37 @@ com_crashlytics_export_strings.xml
212212
crashlytics.properties
213213
crashlytics-build.properties
214214
fabric.properties
215+
216+
217+
#####=== Custom ===#####
218+
# File types:
219+
*.sqlite3
220+
*.db
221+
222+
# Configuration file with private data:
223+
*.env
224+
.env
225+
226+
# Artifacts:
227+
.gitlab/.svn/
228+
artifacts/
229+
230+
# mypy:
231+
.mypy_cache/
232+
233+
# pytest and hypothesis
234+
.pytest_cache/
235+
.hypothesis/
236+
237+
# ipython:
238+
.ipython/
239+
.python_history
240+
241+
# ruff:
242+
.ruff_cache/
243+
244+
# import-linter:
245+
.import_linter_cache/
246+
247+
# safety:
248+
.safety/

.pre-commit-config.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-toml
9+
- id: check-xml
10+
- id: check-merge-conflict
11+
- id: check-symlinks
12+
- id: check-illegal-windows-names
13+
- id: mixed-line-ending
14+
args: ["--fix=lf"]
15+
- id: check-case-conflict
16+
17+
- repo: https://github.com/python-jsonschema/check-jsonschema
18+
rev: 0.33.0
19+
hooks:
20+
- id: check-dependabot
21+
- id: check-github-workflows
22+
- id: check-github-actions
23+
- id: check-gitlab-ci
24+
args: ["--format-regex", "python"]
25+
- id: check-renovate
26+
27+
- repo: https://github.com/rhysd/actionlint
28+
rev: v1.7.7
29+
hooks:
30+
- id: actionlint
31+
additional_dependencies:
32+
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@latest"
33+
34+
- repo: https://github.com/woodruffw/zizmor-pre-commit
35+
rev: v1.6.0
36+
hooks:
37+
- id: zizmor
38+
39+
- repo: https://github.com/shellcheck-py/shellcheck-py
40+
rev: v0.10.0.1
41+
hooks:
42+
- id: shellcheck
43+
args: ["--severity=style"]
44+
45+
# Should be the last:
46+
- repo: meta
47+
hooks:
48+
- id: check-useless-excludes
49+
50+
exclude: ^(\{\{cookiecutter\.project_name\}\})
51+
52+
ci:
53+
autofix_prs: true
54+
autoupdate_schedule: weekly
55+
submodules: false

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ Just like `poetry new` but better.
1717
## Features
1818

1919
- Always [`up-to-date`](https://github.com/wemake-services/wemake-python-package/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot) dependencies with the help of [`@dependabot`](https://dependabot.com/)
20-
- Supports latest `python3.8+`
20+
- Supports latest `python3.10+`
2121
- [`poetry`](https://github.com/python-poetry/poetry) for managing dependencies
2222
- [`mypy`](https://mypy.readthedocs.io) for optional static typing
2323
- [`pytest`](https://github.com/pytest-dev/pytest) for testing
24-
- [`flake8`](https://github.com/PyCQA/flake8) and [`wemake-python-styleguide`](https://github.com/wemake-services/wemake-python-styleguide) for linting
24+
- [`ruff`](https://github.com/astral-sh/ruff) and [`wemake-python-styleguide`](https://github.com/wemake-services/wemake-python-styleguide) for linting
25+
- [`pre-commit` CI](https://pre-commit.ci) with autofixes for your PRs
2526
- [`Github Actions`](https://docs.github.com/en/actions) as the default CI
2627
- [`sphinx`](http://www.sphinx-doc.org/en/master/) and [`readthedocs.org`](https://readthedocs.org/) for documentation
2728
- Easy update process, so your template will always be up-to-date

hooks/post_gen_project.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
77
"""
88

9-
import os
109
import subprocess # noqa: S404
1110
import textwrap
11+
from pathlib import Path
12+
from typing import Final
1213

1314
# Get the root project directory:
14-
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
15-
PROJECT_NAME = '{{ cookiecutter.project_name }}'
15+
PROJECT_DIRECTORY = Path.cwd().resolve(strict=True)
16+
PROJECT_NAME: Final = '{{ cookiecutter.project_name }}'
1617

1718
# We need these values to generate correct license:
18-
LICENSE = '{{ cookiecutter.license }}'
19-
ORGANIZATION = '{{ cookiecutter.organization }}'
19+
LICENSE: Final = '{{ cookiecutter.license }}'
20+
ORGANIZATION: Final = '{{ cookiecutter.organization }}'
2021

2122

22-
def generate_license():
23+
def generate_license() -> None:
2324
"""Generates license file for the project."""
24-
license_result = subprocess.check_output( # noqa: S603, S607
25-
[
25+
license_result = subprocess.check_output( # noqa: S603
26+
[ # noqa: S607
2627
'lice',
2728
LICENSE.lower(),
2829
'-o',
@@ -33,15 +34,19 @@ def generate_license():
3334
universal_newlines=True,
3435
encoding='utf8',
3536
)
36-
with open(
37-
os.path.join(PROJECT_DIRECTORY, 'LICENSE'),
37+
with (PROJECT_DIRECTORY / 'LICENSE').open(
3838
mode='w',
3939
encoding='utf8',
4040
) as license_file:
41-
license_file.write(license_result)
41+
license_file.write(
42+
license_result.strip()
43+
.replace(' \n ', ' \n')
44+
.replace('\n \n', '\n\n'),
45+
)
46+
license_file.write('\n')
4247

4348

44-
def print_futher_instuctions():
49+
def print_futher_instuctions() -> None:
4550
"""Shows user what to do next after project creation."""
4651
message = """
4752
Your project {0} is created.

hooks/pre_gen_project.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import re
22
import sys
3+
from typing import Final
34

4-
MODULE_REGEX = r'^[a-z][a-z0-9\-]+[a-z0-9]$'
5-
MODULE_NAME = '{{ cookiecutter.project_name }}'
5+
MODULE_REGEX: Final = r'^[a-z][a-z0-9\-]+[a-z0-9]$'
6+
MODULE_NAME: Final = '{{ cookiecutter.project_name }}'
67

78

8-
def validate_project_name():
9+
def validate_project_name() -> None:
910
"""
1011
This validator is used to ensure that `project_name` is valid.
1112
@@ -28,13 +29,11 @@ def validate_project_name():
2829
raise ValueError(' '.join(message).format(MODULE_NAME))
2930

3031

31-
validators = (
32-
validate_project_name,
33-
)
32+
validators = (validate_project_name,)
3433

3534
for validator in validators:
3635
try:
3736
validator()
38-
except ValueError as ex:
37+
except ValueError as ex: # noqa: PERF203
3938
print(ex) # noqa: WPS421
4039
sys.exit(1)

0 commit comments

Comments
 (0)