Skip to content

Commit 9832c47

Browse files
refactor, fix, and document Justfile commands (#94)
1 parent 5c75ad5 commit 9832c47

File tree

2 files changed

+73
-36
lines changed

2 files changed

+73
-36
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2323

2424
- Now prompted for the version of PostGIS to use in the project, if `postgis/postgis` is chosen as the PostgreSQL database.
2525
- A new example project has been added to the `examples` directory using PostGIS.
26+
- Two new `Justfile` commands for using `copier`'s recopy command: `copier-recopy` and `copier-recopy-all`.
27+
- All `Justfile` commands now have a short description that is displayed when running `just` (default command) or `just --list`.
2628

2729
### Changed
2830

2931
- PostgreSQL version now takes into account the version of PostGIS, if that option is chosen.
3032

33+
### Fixed
34+
35+
- Removed extra `test` command in `Justfile`.
36+
- Fixed `compose.yml` filename in various `Justfile` commands.
37+
3138
## [2024.9]
3239

3340
### Changed

src/django_twc_project/Justfile.jinja

+66-36
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,36 @@ set dotenv-load := true
22

33
export DATABASE_URL := env_var_or_default('DATABASE_URL', '{{ postgres_uri_scheme }}://postgres:postgres@db:5432/postgres')
44

5+
# List all available commands
56
@_default:
67
just --list
78

89
# ----------------------------------------------------------------------
910
# DEPENDENCIES
1011
# ----------------------------------------------------------------------
1112

13+
# Bootstrap local development environment
1214
bootstrap:
13-
python -m pip install --upgrade pip uv
15+
@just pup
1416
@just install
1517

18+
# Generate requirements file
1619
lock *ARGS:
1720
python -m uv pip compile {% raw %}{{ ARGS }}{% endraw %} --generate-hashes requirements.in --output-file requirements.txt
1821

22+
# Install dependencies
1923
install *ARGS:
2024
python -m uv pip install --upgrade -r requirements.txt
2125

26+
# Generate and upgrade dependencies
2227
upgrade:
2328
@just lock --upgrade
2429

30+
# Install and update dependency tools
2531
pup:
2632
python -m pip install --upgrade pip uv
2733

34+
# Update local development environment
2835
update:
2936
@just pup
3037
@just upgrade
@@ -62,55 +69,66 @@ coverage:
6269
docker compose run --rm --no-deps -e PWDEBUG=1 app pytest {% raw %}{{ ARGS }}{% endraw %}
6370
{%- endif %}
6471

72+
# Run mypy on project
6573
types:
6674
just command python -m mypy .
6775

6876
# ----------------------------------------------------------------------
6977
# DJANGO
7078
# ----------------------------------------------------------------------
7179

80+
# Run a Django management command
7281
@manage *COMMAND:
7382
just command python -m manage {% raw %}{{ COMMAND }}{% endraw %}
7483

84+
# Alias for makemigrations
7585
alias mm := makemigrations
7686

87+
# Generate Django migrations
7788
makemigrations *APPS:
7889
@just manage makemigrations {% raw %}{{ APPS }}{% endraw %}
7990

91+
# Run Django migrations
8092
migrate *ARGS:
8193
@just manage migrate {% raw %}{{ ARGS }}{% endraw %}
8294

95+
# Open a Django shell using django-extensions shell_plus command
8396
shell-plus:
8497
@just manage shell_plus
8598

99+
# Quickly create a superuser with the provided credentials
86100
createsuperuser USERNAME="admin" EMAIL="" PASSWORD="admin":
87101
docker compose run --rm --no-deps app /bin/bash -c 'echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('"'"'{% raw %}{{ USERNAME }}{% endraw %}'"'"', '"'"'{% raw %}{{ EMAIL }}{% endraw %}'"'"', '"'"'{% raw %}{{ PASSWORD }}{% endraw %}'"'"') if not User.objects.filter(username='"'"'{% raw %}{{ USERNAME }}{% endraw %}'"'"').exists() else None" | python manage.py shell'
88102

103+
# Reset a user's password
89104
resetuserpassword USERNAME="admin" PASSWORD="admin":
90105
docker compose run --rm --no-deps app /bin/bash -c 'echo "from django.contrib.auth import get_user_model; User = get_user_model(); user = User.objects.get(username='"'"'{% raw %}{{ USERNAME }}{% endraw %}'"'"'); user.set_password('"'"'{% raw %}{{ PASSWORD }}{% endraw %}'"'"'); user.save()" | python manage.py shell'
91106

92-
# ----------------------------------------------------------------------
93-
# DOCS
94-
# ----------------------------------------------------------------------
95-
96-
_cog:
97-
cog -r docs/just.md
98-
107+
# Graph models using django-extensions graph_models command
99108
graph:
100109
just manage graph_models users \
101110
--exclude-models AbstractUser \
102111
--group-models \
103112
--output ./docs/applications/images/users.svg
104113

105-
docs-lock *ARGS:
106-
python -m uv pip compile {% raw %}{{ ARGS }}{% endraw %} --generate-hashes docs/requirements.in --output-file docs/requirements.txt
114+
# ----------------------------------------------------------------------
115+
# DOCS
116+
# ----------------------------------------------------------------------
107117

108-
docs-upgrade:
109-
@just docs-lock --upgrade
118+
# Build documentation using Sphinx
119+
docs-build LOCATION="docs/_build/html":
120+
just _cog
121+
sphinx-build docs {% raw %}{{ LOCATION }}{% endraw %}
110122

123+
# Install documentation dependencies
111124
docs-install:
112125
python -m uv pip install --upgrade -r docs/requirements.txt
113126

127+
# Generate documentation requirements
128+
docs-lock *ARGS:
129+
python -m uv pip compile {% raw %}{{ ARGS }}{% endraw %} --generate-hashes docs/requirements.in --output-file docs/requirements.txt
130+
131+
# Serve documentation locally
114132
docs-serve:
115133
#!/usr/bin/env sh
116134
just _cog
@@ -120,21 +138,24 @@ docs-serve:
120138
sphinx-autobuild docs docs/_build/html --host "localhost"
121139
fi
122140

123-
docs-build LOCATION="docs/_build/html":
124-
just _cog
125-
sphinx-build docs {% raw %}{{ LOCATION }}{% endraw %}
141+
# Generate and upgrade documentation dependencies
142+
docs-upgrade:
143+
@just docs-lock --upgrade
144+
145+
_cog:
146+
cog -r docs/just.md
126147

127148
# ----------------------------------------------------------------------
128149
# DOCKER
129150
# ----------------------------------------------------------------------
130151

131-
# Build services using docker-compose
152+
# Build services using docker compose
132153
build *ARGS:
133154
docker compose build {% raw %}{{ ARGS }}{% endraw %}
134155

135-
# Build production stack using docker-compose
156+
# Build production stack using docker compose
136157
build-prod:
137-
docker compose -f docker-compose.yml -f docker-compose.prod.yml build
158+
docker compose -f compose.yml -f compose.prod.yml build
138159

139160
# Stop and remove all containers, networks, images, and volumes
140161
clean:
@@ -148,7 +169,7 @@ command *ARGS:
148169
console:
149170
docker compose run --rm --no-deps app /bin/bash
150171

151-
# Stop and remove all containers defined in docker-compose
172+
# Stop and remove all containers defined in docker compose
152173
down *ARGS:
153174
docker compose down {% raw %}{{ ARGS }}{% endraw %}
154175

@@ -160,7 +181,7 @@ logs *ARGS:
160181
ps:
161182
docker compose ps
162183

163-
# Pull the latest versions of all images defined in docker-compose
184+
# Pull the latest versions of all images defined in docker compose
164185
pull:
165186
docker compose pull
166187

@@ -176,11 +197,11 @@ shell *ARGS="app":
176197
shell-db:
177198
docker compose run --rm --no-deps db psql -d {% raw %}{{ DATABASE_URL }}{% endraw %}
178199

179-
# Start services using docker-compose, defaulting to detached mode
200+
# Start services using docker compose, defaulting to detached mode
180201
start *ARGS="--detach":
181202
@just up {% raw %}{{ ARGS }}{% endraw %}
182203

183-
# Start the full production stack using docker-compose, defaulting to detached mode
204+
# Start the full production stack using docker compose, defaulting to detached mode
184205
start-prod *ARGS="--detach":
185206
@just up-prod {% raw %}{{ ARGS }}{% endraw %}
186207

@@ -192,20 +213,20 @@ stop:
192213
tail *ARGS:
193214
@just logs '--follow {% raw %}{{ ARGS }}{% endraw %}'
194215

195-
# Start services using docker-compose, with optional arguments
216+
# Start services using docker compose, with optional arguments
196217
up *ARGS:
197218
docker compose up {% raw %}{{ ARGS }}{% endraw %}
198219

199-
# Start the full production stack using docker-compose
220+
# Start the full production stack using docker compose
200221
up-prod *ARGS:
201-
docker compose -f docker-compose.yml -f docker-compose.prod.yml up {% raw %}{{ ARGS }}{% endraw %}
222+
docker compose -f compose.yml -f compose.prod.yml up {% raw %}{{ ARGS }}{% endraw %}
202223

203224

204225
# ----------------------------------------------------------------------
205226
# POSTGRES BACKUP AND RESTORE
206227
# ----------------------------------------------------------------------
207228

208-
# dump our local database to file
229+
# Dump our local database to file
209230
pg_dump database_url=DATABASE_URL file='db.dump':
210231
docker compose run \
211232
--rm \
@@ -217,12 +238,12 @@ pg_dump database_url=DATABASE_URL file='db.dump':
217238
--format=c \
218239
--verbose
219240

220-
# dump our production database to file
241+
# Dump our production database to file
221242
pg_dump_prod file='production.dump':
222243
set PROD_DATABASE_URL := "{% raw %}{{ env_var('PROD_DATABASE_URL') }}{% endraw %}"
223244
@just pg_dump ${PROD_DATABASE_URL} {% raw %}{{ file }}{% endraw %}
224245

225-
# restore database backup to our local database
246+
# Restore database backup to our local database
226247
pg_restore file='db.dump':
227248
docker compose run \
228249
--rm \
@@ -240,6 +261,7 @@ pg_restore file='db.dump':
240261
# UTILS
241262
# ----------------------------------------------------------------------
242263

264+
# Sync .env* files
243265
envsync:
244266
#!/usr/bin/env python
245267
from pathlib import Path
@@ -257,26 +279,34 @@ envsync:
257279
lines.sort()
258280
envfile_example.write_text(''.join(lines))
259281

260-
# format justfile
282+
# Format justfile
261283
fmt:
262284
just --fmt --unstable
263285

264-
# run pre-commit on all files
286+
# Run pre-commit on all files
265287
lint:
266288
pre-commit run --all-files
267289

268290
# ----------------------------------------------------------------------
269291
# COPIER
270292
# ----------------------------------------------------------------------
271293

272-
# create a copier answers file
294+
# Create a copier answers file
273295
copier-copy TEMPLATE_PATH DESTINATION_PATH=".":
274-
pipx run copier copy {% raw %}{{ TEMPLATE_PATH }}{% endraw %} {% raw %}{{ DESTINATION_PATH }}{% endraw %}
296+
python -m copier copy --trust {% raw %}{{ TEMPLATE_PATH }}{% endraw %} {% raw %}{{ DESTINATION_PATH }}{% endraw %}
297+
298+
# Recopy the project from the original template
299+
copier-recopy ANSWER_FILE *ARGS:
300+
python -m copier recopy --trust --answers-file {% raw %}{{ ANSWERS_FILE }}{% endraw %} {% raw %}{{ ARGS }}{% endraw %}
301+
302+
# Loop through all answers files and recopy the project using copier
303+
@copier-recopy-all *ARGS:
304+
for file in `ls .copier/`; do just copier-recopy .copier/$file "{% raw %}{{ ARGS }}{% endraw %}"; done
275305

276-
# update the project using a copier answers file
306+
# Update the project using a copier answers file
277307
copier-update ANSWERS_FILE *ARGS:
278-
pipx run copier update --answers-file {% raw %}{{ ANSWERS_FILE }}{% endraw %} {% raw %}{{ ARGS }}{% endraw %}
308+
python -m copier update --trust --answers-file {% raw %}{{ ANSWERS_FILE }}{% endraw %} {% raw %}{{ ARGS }}{% endraw %}
279309

280-
# loop through all answers files and update the project using copier
310+
# Loop through all answers files and update the project using copier
281311
@copier-update-all *ARGS:
282-
for file in `ls .copier-answers/`; do just copier-update .copier-answers/$file "{% raw %}{{ ARGS }}{% endraw %}"; done
312+
for file in `ls .copier/`; do just copier-update .copier/$file "{% raw %}{{ ARGS }}{% endraw %}"; done

0 commit comments

Comments
 (0)