From 6446f911ebc16f7e3f86b52f96d43d1b1637068f Mon Sep 17 00:00:00 2001 From: anthonyA1214 Date: Fri, 27 Nov 2026 20:18:24 +0800 Subject: [PATCH] chore(dev): expand just recipes and configure model graphs - Group justfile recipes (dev, db, extensions, deps, quality, hooks) - Add LAN and runserver_plus variants, and bind local runs explicitly to 127.0.0.1 - Use shell_plus for `just shell`; keep `shell-plain` for the default - Add recipes for database, dependency, coverage, CI, and django-extensions tasks, with a confirmation prompt on `reset-db` - Add GRAPH_MODELS dev settings to group models and exclude framework and bookkeeping models - Add pydot and pyparsing dev dependencies and update uv.lock --- config/settings/dev.py | 16 +++++ justfile | 141 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 2 + uv.lock | 25 ++++++++ 4 files changed, 181 insertions(+), 3 deletions(-) diff --git a/config/settings/dev.py b/config/settings/dev.py index 6bd4e8c..6d17628 100644 --- a/config/settings/dev.py +++ b/config/settings/dev.py @@ -9,3 +9,19 @@ INSTALLED_APPS = [*INSTALLED_APPS, "django_extensions"] PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] + +GRAPH_MODELS = { + "all_applications": True, + "group_models": True, + "exclude_models": ( + "EmailAddress," + "EmailConfirmation," + "Group," + "Permission," + "ContentType," + "Session," + "Site," + "ChangeSet," + "SoftDeleteRecord," + ), +} diff --git a/justfile b/justfile index c90307e..9abfdc0 100644 --- a/justfile +++ b/justfile @@ -21,15 +21,58 @@ setup: # Dev commands # ========================================== -# Run dev server (just run 3000) +# Run dev server on localhost (just run 3000) +[group('dev')] run port="8000": - {{py}} runserver {{port}} + {{py}} runserver 127.0.0.1:{{port}} -# Django shell +# Run dev server exposed on the network/LAN (just run-lan 3000) +[group('dev')] +run-lan port="8000": + {{py}} runserver 0.0.0.0:{{port}} + +# Run with Werkzeug debugger (django-extensions) +[group('dev')] +runplus port="8000": + {{py}} runserver_plus 127.0.0.1:{{port}} + +# Run with Werkzeug debugger, exposed on the network/LAN +[group('dev')] +runplus-lan port="8000": + {{py}} runserver_plus 0.0.0.0:{{port}} + +# Django shell (shell_plus auto-imports all models) +[group('dev')] shell: + {{py}} shell_plus + +# Plain Django shell +[group('dev')] +shell-plain: {{py}} shell +# Open the database shell (psql/sqlite3) +[group('dev')] +dbshell: + {{py}} dbshell + +# Create a superuser +[group('dev')] +superuser: + {{py}} createsuperuser + +# Collect static files +[group('dev')] +collectstatic: + {{py}} collectstatic --noinput + +# Check the project for problems (just check --deploy) +[group('dev')] +check *args: + {{py}} check {{args}} + # Catch-all (just manage showmigrations) +[group('dev')] manage *args: {{py}} {{args}} @@ -39,47 +82,139 @@ manage *args: # ========================================== # Make migrations (just makemigrations blog) +[group('db')] makemigrations *args: {{py}} makemigrations {{args}} # Apply migrations +[group('db')] migrate *args: {{py}} migrate {{args}} # Show migrations +[group('db')] showmigrations *args: {{py}} showmigrations {{args}} +# Check for missing migrations (good for CI) +[group('db')] +migrations-check: + {{py}} makemigrations --check --dry-run + +# Drop and recreate the schema, then migrate (Postgres) - DESTRUCTIVE +[group('db')] +[confirm("This will DELETE ALL data in the database schema. Continue?")] +reset-db: + {{py}} reset_schema --noinput + {{py}} migrate + + +# ========================================== +# django-extensions goodies +# ========================================== + +# List all URLs +[group('extensions')] +urls: + {{py}} show_urls + +# Print effective settings (just settings DATABASES) +[group('extensions')] +settings *args: + {{py}} diffsettings {{args}} + +# Generate an ER diagram (needs graphviz + pydot) +[group('extensions')] +graph-models app="": + {{py}} graph_models {{app}} -o models.png + +# Validate templates +[group('extensions')] +validate-templates: + {{py}} validate_templates + +# Clear all Python cache files +[group('extensions')] +clean-pyc: + {{py}} clean_pyc + + +# ========================================== +# Dependencies +# ========================================== + +# Add a dependency (just add requests / just add --dev pytest) +[group('deps')] +add *args: + uv add {{args}} + +# Remove a dependency +[group('deps')] +remove *args: + uv remove {{args}} + +# Sync the environment from the lockfile +[group('deps')] +sync: + uv sync + +# Upgrade all dependencies +[group('deps')] +upgrade: + uv lock --upgrade + uv sync + + # ========================================== # Test and quality commands # ========================================== # Run tests (just test blog --keepdb) +[group('quality')] test *args: {{py}} test {{args}} +# Run tests with coverage +[group('quality')] +cov *args: + uv run coverage run manage.py test {{args}} + uv run coverage report + # Format and autofix +[group('quality')] fmt: uv run ruff format . uv run ruff check --fix . # Lint only +[group('quality')] lint: uv run ruff check . +# Full CI check: lint + format check + migrations + tests +[group('quality')] +ci: + uv run ruff check . + uv run ruff format --check . + {{py}} makemigrations --check --dry-run + {{py}} test --parallel + # =========================================== # Pre-commit Hooks # =========================================== # Install pre-commit hooks +[group('hooks')] pre-commit-install: uv run pre-commit install # Update pre-commit hooks to latest versions +[group('hooks')] pre-commit-update: uv run pre-commit autoupdate # Run pre-commit on all files +[group('hooks')] pre-commit-all: uv run pre-commit run --all-files diff --git a/pyproject.toml b/pyproject.toml index 3e5fcab..e3c41f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,8 @@ dev = [ "factory-boy>=3.3.3", "mypy>=2.1.0", "pre-commit>=4.6.0", + "pydot>=4.0.1", + "pyparsing>=3.3.3", "ruff>=0.15.21", ] diff --git a/uv.lock b/uv.lock index 0f403bf..8588ed8 100644 --- a/uv.lock +++ b/uv.lock @@ -62,6 +62,8 @@ dev = [ { name = "factory-boy" }, { name = "mypy" }, { name = "pre-commit" }, + { name = "pydot" }, + { name = "pyparsing" }, { name = "ruff" }, ] @@ -95,6 +97,8 @@ dev = [ { name = "factory-boy", specifier = ">=3.3.3" }, { name = "mypy", specifier = ">=2.1.0" }, { name = "pre-commit", specifier = ">=4.6.0" }, + { name = "pydot", specifier = ">=4.0.1" }, + { name = "pyparsing", specifier = ">=3.3.3" }, { name = "ruff", specifier = ">=0.15.21" }, ] @@ -1365,6 +1369,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/3a/c0/38c505004969c4641c3a077a8e72e354f02d5c06d8f51d7a103699704772/pydantic_core-2.50.4-cp315-cp315t-win_arm64.whl", hash = "sha256:da779ae50b46f3f7d1e1b5f362fdc0ad376a49fd55f6f3122dc2b6149936cdf7", size = 2179018, upload-time = "2026-11-05T09:14:54.448Z" }, ] +[[package]] +name = "pydot" +version = "4.0.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pyparsing" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/50/35/b17cb89ff865484c6a20ef46bf9d95a5f07328292578de0b295f4a6beec2/pydot-4.0.1.tar.gz", hash = "sha256:c2148f681c4a33e08bf0e26a9e5f8e4099a82e0e2a068098f32ce86577364ad5", size = 162594, upload-time = "2025-06-17T20:09:56.454Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/32/a7125fb28c4261a627f999d5fb4afff25b523800faed2c30979949d6facd/pydot-4.0.1-py3-none-any.whl", hash = "sha256:869c0efadd2708c0be1f916eb669f3d664ca684bc57ffb7ecc08e70d5e93fee6", size = 37087, upload-time = "2025-06-17T20:09:55.25Z" }, +] + [[package]] name = "pyjwt" version = "2.15.1" @@ -1391,6 +1407,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/51/ad/2cf6d3fa2fae5c79e1ed9960c0d42badd0f94d81dd12b50604cdc839e648/pyopenssl-26.4.0-py3-none-any.whl", hash = "sha256:f0eb0cb2d581d3ad2b9c489468485e7f2ab6727d08401bcf9d824c3caddf3c1c", size = 56026, upload-time = "2026-08-01T19:50:48.94Z" }, ] +[[package]] +name = "pyparsing" +version = "3.3.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e4/11/b213bebff182584360cb8d17c72c1677fec5c5c228de439e63bcf8ab1c8f/pyparsing-3.3.3.tar.gz", hash = "sha256:928ae7e20211f3b6f3915a72f06a0cfd29ab9d24279dd6346b6b1a7146397d36", size = 1050487, upload-time = "2026-09-20T20:59:05.609Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/38/bb/d215ee7c73b61497b28a5503f9f53523f294fcc936762b7caf90e0c1c2b5/pyparsing-3.3.3-py3-none-any.whl", hash = "sha256:ece8c00a69cf01b45d0b1dedabb469c90d8caf996d4fda40f147627a122849a4", size = 126420, upload-time = "2026-09-20T20:59:04.025Z" }, +] + [[package]] name = "python-dateutil" version = "2.9.0.post0"