Skip to content

Commit

Permalink
🚜 ⬆️ Update manage py and pyproject (#28)
Browse files Browse the repository at this point in the history
* 🚜 Rebuild manage.py from Django's default

* 🚜 Update pyproject based on ruff's latest preferences

* ⬆️ Bumps and adds more plugins

* 👕 Lints

* 👕 Lints
  • Loading branch information
jefftriplett authored May 26, 2024
1 parent 13a46c6 commit cce19d0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
23 changes: 14 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.17.0
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
alias: autoformat
- repo: https://github.com/psf/black
rev: 24.4.2
- id: django-upgrade
args: [--target-version, "5.0"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: black
alias: autoformat
- repo: https://github.com/charliermarsh/ruff-pre-commit
- id: pyupgrade
args: [--py312-plus]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
hooks:
- id: ruff
alias: autoformat
args: [--fix]
- id: ruff-format
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
Expand Down
29 changes: 15 additions & 14 deletions manage.py-tpl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

if __name__ == "__main__":

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
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?"
)
raise
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
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
70 changes: 33 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,52 @@ target-version = ["py312"]

[tool.coverage.run]
omit = [
"*/admin.py",
"*/manage.py",
"*/migrations/*",
"*/tests/*",
"conftest.py",
"*/admin.py",
"*/manage.py",
"*/migrations/*",
"*/tests/*",
"conftest.py"
]

[tool.pytest.ini_options]
addopts = "--cov --nomigrations --reuse-db"
DJANGO_SETTINGS_MODULE = "config.settings"
addopts = "--cov --nomigrations --reuse-db"
norecursedirs = ".git* frontend requirements templates"
python_files = "test_*.py"

[tool.ruff]
# Enable Pyflakes `E` and `F` codes by default.
select = ["E", "F"]
ignore = ["E501", "E741"] # temporary

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".github",
".hg",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"build",
"dist",
"migrations",
"node_modules",
"static",
".bzr",
".direnv",
".eggs",
".git",
".github",
".hg",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"build",
"dist",
"migrations",
"node_modules",
"static"
]

per-file-ignores = {}

# Same as Black.
line-length = 120
# Assume Python 3.12.
target-version = "py312"

[tool.ruff.lint]
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.12.
target-version = "py312"
# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F"]
ignore = ["E501", "E741"] # temporary
per-file-ignores = {}
# Enable Pyflakes `E` and `F` codes by default.
select = ["E", "F"]
unfixable = []

0 comments on commit cce19d0

Please sign in to comment.