Skip to content

Commit

Permalink
cookiecutters: Use ruff and uv. Simplify coverage.
Browse files Browse the repository at this point in the history
- build: Add .python-version. Use coverage directly, instead of pytest-cov. Remove linters from dev requirements.
- ci: Use official coveralls action. Test on PyPy 3.10.
- chore: Switch to ruff and uv.

ci: Add pre-commit job to automerge workflow, for consistency
chore: Switch to pyproject.toml
  • Loading branch information
jpmckinney committed Sep 11, 2024
1 parent 565ae17 commit 82048eb
Show file tree
Hide file tree
Showing 30 changed files with 211 additions and 356 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
precommit:
if: ${{ github.event.pull_request.user.login == 'pre-commit-ci[bot]' }}
runs-on: ubuntu-latest
steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr review --approve ${{ github.event.pull_request.html_url }}
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
8 changes: 5 additions & 3 deletions cookiecutter-django/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def set_secret_key(path):

def use_fathom(enabled):
if enabled:
print(dedent(
"""
print(
dedent(
"""
{%- raw %}
Run python manage.py startapp and add a fathom.html file to its templates/ directory:
Expand All @@ -33,7 +34,8 @@ def use_fathom(enabled):
{% include 'fathom.html' %}
{%- endraw %}
""" # noqa: E501
))
)
)
else:
os.remove(os.path.join("core", "context_processors.py"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jobs:
./manage.py makemigrations --check --dry-run
./manage.py check --fail-level WARNING
coverage run --source core manage.py test
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
- uses: coverallsapp/github-action@v2
services:
postgres:
image: postgres:15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
cache: pip
cache-dependency-path: '**/requirements*.txt'
- id: changed-files
uses: tj-actions/changed-files@v40
- uses: pre-commit/[email protected].0
uses: tj-actions/changed-files@v45
- uses: pre-commit/[email protected].1
continue-on-error: true
with:
extra_args: pip-compile --files ${{ steps.changed-files.outputs.all_changed_files }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
ci:
autoupdate_schedule: quarterly
skip: [pip-compile]
default_language_version:
python: python3.11
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-comprehensions]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/jazzband/pip-tools
rev: 7.3.0
- id: ruff
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.4
hooks:
- id: pip-compile
name: pip-compile requirements.in
files: ^requirements\.(in|txt)$
args: [requirements.in, -o, requirements.txt]
- id: pip-compile
name: pip-compile requirements_dev.in
args: [requirements_dev.in, -o, requirements_dev.txt]
files: ^requirements(_dev)?\.(in|txt)$
args: [requirements_dev.in]
exclude: /migrations/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
39 changes: 33 additions & 6 deletions cookiecutter-django/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
[tool.black]
[project]
name = "{{ cookiecutter.project_slug }}"
version = "0.0.0"

[tool.ruff]
line-length = 119
exclude = '/(migrations|node_modules)/'
target-version = "py311"

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN", "COM", "EM",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191", "D206", "Q000", "Q001", "Q002", "Q003", "ISC001",
"D203", "D212", # ignore incompatible rules
"D200", "D205", # documentation preferences
"C901", "PLR091", # complexity preferences
"ARG001", "ARG002", "DJ008", "RUF012", "SLF001", # Django
]

[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["copyright"]

[tool.isort]
profile = 'black'
line_length = 119
skip = ['migrations']
[tool.ruff.lint.per-file-ignores]
"docs/conf.py" = ["INP001"] # no __init__.py file
"*/management/commands/*" = ["INP001"] # no __init__.py file
"*/migrations/*" = ["E501"]
"tests/*" = [
"D", # docstring
"ARG001", # pytest fixtures
"PLR0913", # Too many arguments
"PLR2004", # Magic value used
"PT", # Django
"S101", # assert
]

[tool.coverage.run]
omit = ['*/migrations/*']
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#
# This file is autogenerated by pip-compile with Python {{ cookiecutter.python_version }}
# by the following command:
#
# pip-compile
#
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
asgiref==3.7.2
# via django
certifi==2024.7.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
-r requirements.txt
black
coverage
coveralls
flake8
isort
pip-tools
pre-commit
Original file line number Diff line number Diff line change
@@ -1,114 +1,34 @@
#
# This file is autogenerated by pip-compile with Python {{ cookiecutter.python_version }}
# by the following command:
#
# pip-compile requirements_dev.in
#
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_dev.in -o requirements_dev.txt
asgiref==3.7.2
# via
# -r requirements.txt
# django
backports-entry-points-selectable==1.1.1
# via virtualenv
black==24.3.0
# via -r requirements_dev.in
build==1.0.3
# via pip-tools
certifi==2024.7.4
# via
# -r requirements.txt
# requests
# sentry-sdk
cfgv==3.3.1
# via pre-commit
charset-normalizer==2.0.7
# via requests
click==8.0.3
# via
# black
# pip-tools
coverage[toml]==6.1.2
# via
# -r requirements_dev.in
# coveralls
coveralls==4.0.1
coverage==7.6.1
# via -r requirements_dev.in
distlib==0.3.3
# via virtualenv
dj-database-url==2.1.0
# via -r requirements.txt
django==4.2.15
# via
# -r requirements.txt
# dj-database-url
docopt==0.6.2
# via coveralls
filelock==3.4.0
# via virtualenv
flake8==4.0.1
# via -r requirements_dev.in
identify==2.3.6
# via pre-commit
idna==3.7
# via requests
isort==5.10.1
# via -r requirements_dev.in
mccabe==0.6.1
# via flake8
mypy-extensions==0.4.3
# via black
nodeenv==1.6.0
# via pre-commit
packaging==23.2
# via
# black
# build
pathspec==0.9.0
# via black
pip-tools==7.3.0
# via -r requirements_dev.in
platformdirs==2.4.0
# via
# black
# virtualenv
pre-commit==3.6.0
# via -r requirements_dev.in
psycopg2==2.9.2
# via -r requirements.txt
pycodestyle==2.8.0
# via flake8
pyflakes==2.4.0
# via flake8
pyproject-hooks==1.0.0
# via build
pyyaml==6.0
# via pre-commit
requests==2.32.2
# via coveralls
sentry-sdk==2.10.0
# via -r requirements.txt
six==1.16.0
# via virtualenv
sqlparse==0.5.0
# via
# -r requirements.txt
# django
tomli==1.2.2
# via coverage
typing-extensions==4.9.0
# via
# -r requirements.txt
# dj-database-url
urllib3==2.2.2
# via
# -r requirements.txt
# requests
# sentry-sdk
virtualenv==20.10.0
# via pre-commit
wheel==0.38.1
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
4 changes: 0 additions & 4 deletions cookiecutter-django/{{cookiecutter.project_slug}}/setup.cfg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
{%- if cookiecutter.os_independent == "y" %}
os: [macos-latest, windows-latest, ubuntu-latest]
{%- endif %}
python-version: [3.8, 3.9, '3.10', '3.11', '3.12'{% if cookiecutter.pypy == "y" %}, pypy-3.9{% endif %}]
python-version: [3.8, 3.9, '3.10', '3.11', '3.12'{% if cookiecutter.pypy == "y" %}, pypy-3.10{% endif %}]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -26,9 +26,5 @@ jobs:
cache: pip
cache-dependency-path: setup.cfg
- run: pip install .[test]
- run: pytest -W error --cov {{ cookiecutter.package_name }}
- env:
{%- raw %}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
{%- endraw %}
run: coveralls --service=github
- run: coverage run --source={{ cookiecutter.package_name }} pytest -W error
- uses: coverallsapp/github-action@v2
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-comprehensions]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies: [toml]
files: ^(?!tests)
- id: ruff
- id: ruff-format
Loading

0 comments on commit 82048eb

Please sign in to comment.