diff --git a/Makefile b/Makefile index 63bd2f5..fe1c96a 100644 --- a/Makefile +++ b/Makefile @@ -3,36 +3,34 @@ SHELL=/bin/bash -eu -o pipefail -.venv/bin/activate: - python3.9 -m venv --prompt $(shell basename $(shell pwd)) .venv - -.PHONY: install -install: .venv/bin/activate # Install Python dependencies - ./.venv/bin/pip install -r requirements.txt - ./.venv/bin/pip install -e . - -.PHONY: install-dev -install-dev: .venv/bin/activate # Install Python dependencies - ./.venv/bin/pip install -r requirements/dev.txt - ./.venv/bin/pip install -e . - -upgrade-pip: - pip install --upgrade pip wheel setuptools pip-tools - -requirements.txt: pyproject.toml +requirements.txt: pyproject.toml # Generate requirements.txt (and requirements-dev.txt) from pyproject.toml ./bin/lock-requirements.sh .PHONY: upgrade-requirements -upgrade-requirements: +upgrade-requirements: # Upgrade all requirements to the latest version ./bin/lock-requirements.sh --upgrade {{ project_name }}.yml: ./.venv/bin/generate-config > $@ + + .PHONY: fmt -fmt: +fmt: # Format Python code ruff format . +.PHONY: lint +lint: # Lint Python code + ruff check . + +.PHONY: fix +fix: # Fix linting errors + ruff check --fix . + +.PHONY: test +test: # Run tests + python manage.py test --parallel + .PHONY: help help: @echo -e "Available make commands:" diff --git a/manage.py b/manage.py index 77746e5..8ffcbd3 100755 --- a/manage.py +++ b/manage.py @@ -4,17 +4,10 @@ import sys -def main(): +def main() -> None: """Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc + from django.core.management import execute_from_command_line execute_from_command_line(sys.argv) diff --git a/project_name/config.py b/project_name/config.py index 9870dc8..6fac283 100644 --- a/project_name/config.py +++ b/project_name/config.py @@ -1,6 +1,5 @@ import base64 import os -from typing import List from pathlib import Path from goodconf import Field, GoodConf @@ -14,7 +13,7 @@ class AppConfig(GoodConf): """Configuration for {{ project_name }}""" DEBUG: bool = False - ALLOWED_HOSTS: List[str] = Field( + ALLOWED_HOSTS: list[str] = Field( default=["*"], description="Hosts allowed to serve the site " "https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#allowed-hosts", @@ -40,7 +39,3 @@ class Config: config = AppConfig() - - -def generate_config(): - print(AppConfig.generate_yaml(DEBUG=True)) diff --git a/project_name/settings.py b/project_name/settings.py index 2b06320..6bccf76 100644 --- a/project_name/settings.py +++ b/project_name/settings.py @@ -10,6 +10,7 @@ https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ """ +import re from pathlib import Path import dj_database_url @@ -137,7 +138,7 @@ STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" # Match filename with 12 hex digits before the extension -WHITENOISE_IMMUTABLE_FILE_TEST = lambda path, url: re.match( # noqa: E731 +WHITENOISE_IMMUTABLE_FILE_TEST = lambda _, url: re.match( # noqa: E731 r"^.+\.[0-9a-f]{12}\..+$", url ) diff --git a/project_name/wsgi.py b/project_name/wsgi.py index e001d04..c5703e7 100644 --- a/project_name/wsgi.py +++ b/project_name/wsgi.py @@ -20,10 +20,6 @@ # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. -from django.core.wsgi import get_wsgi_application +from django.core.wsgi import get_wsgi_application # noqa: E402 application = get_wsgi_application() - -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application) diff --git a/pyproject.toml b/pyproject.toml index 2e3bea1..3422299 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,8 +29,10 @@ packages = { "find" = { } } include-package-data = true [tool.ruff] -target-version = "py12" +target-version = "py312" exclude = ["migrations"] + +[tool.ruff.lint] select = ["ALL"] ignore = [ "ANN101", # Missing Type Annotation for "self" @@ -38,6 +40,7 @@ ignore = [ "ARG001", # Unused function argument (request, ...) "ARG002", # Unused method argument (*args, **kwargs) "D", # Missing or badly formatted docstrings + "E501", # Let the formatter handle long lines "FBT", # Flake Boolean Trap (don't use arg=True in functions) "RUF012", # Mutable class attributes https://github.com/astral-sh/ruff/issues/5243 @@ -45,7 +48,7 @@ ignore = [ "ISC001", # (ruff format) Checks for implicitly concatenated strings on a single line ] -[tool.ruff.extend-per-file-ignores] +[tool.ruff.lint.extend-per-file-ignores] # Also ignore `E402` in all `__init__.py` files. "test_*.py" = [ "S101", # S101 Use of `assert` detected