Skip to content

Commit

Permalink
Add linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Feb 10, 2024
1 parent f37b8c9 commit f8ed649
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 42 deletions.
36 changes: 17 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
11 changes: 2 additions & 9 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 1 addition & 6 deletions project_name/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import base64
import os
from typing import List
from pathlib import Path

from goodconf import Field, GoodConf
Expand All @@ -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",
Expand All @@ -40,7 +39,3 @@ class Config:


config = AppConfig()


def generate_config():
print(AppConfig.generate_yaml(DEBUG=True))
3 changes: 2 additions & 1 deletion project_name/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
"""

import re
from pathlib import Path

import dj_database_url
Expand Down Expand Up @@ -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
)

Expand Down
6 changes: 1 addition & 5 deletions project_name/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ 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"
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`"
"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

"COM812", # (ruff format) Checks for the absence of trailing commas
"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
Expand Down

0 comments on commit f8ed649

Please sign in to comment.