@@ -2,29 +2,36 @@ set dotenv-load := true
2
2
3
3
export DATABASE_URL := env_var_or_default('DATABASE_URL', '{{ postgres_uri_scheme }}://postgres:postgres@db:5432/postgres')
4
4
5
+ # List all available commands
5
6
@_default:
6
7
just --list
7
8
8
9
# ----------------------------------------------------------------------
9
10
# DEPENDENCIES
10
11
# ----------------------------------------------------------------------
11
12
13
+ # Bootstrap local development environment
12
14
bootstrap:
13
- python -m pip install --upgrade pip uv
15
+ @just pup
14
16
@just install
15
17
18
+ # Generate requirements file
16
19
lock *ARGS:
17
20
python -m uv pip compile {% raw %} {{ ARGS }}{% endraw %} --generate-hashes requirements.in --output-file requirements.txt
18
21
22
+ # Install dependencies
19
23
install *ARGS:
20
24
python -m uv pip install --upgrade -r requirements.txt
21
25
26
+ # Generate and upgrade dependencies
22
27
upgrade:
23
28
@just lock --upgrade
24
29
30
+ # Install and update dependency tools
25
31
pup:
26
32
python -m pip install --upgrade pip uv
27
33
34
+ # Update local development environment
28
35
update:
29
36
@just pup
30
37
@just upgrade
@@ -62,55 +69,66 @@ coverage:
62
69
docker compose run --rm --no-deps -e PWDEBUG=1 app pytest {% raw %} {{ ARGS }}{% endraw %}
63
70
{% - endif %}
64
71
72
+ # Run mypy on project
65
73
types:
66
74
just command python -m mypy .
67
75
68
76
# ----------------------------------------------------------------------
69
77
# DJANGO
70
78
# ----------------------------------------------------------------------
71
79
80
+ # Run a Django management command
72
81
@manage *COMMAND:
73
82
just command python -m manage {% raw %} {{ COMMAND }}{% endraw %}
74
83
84
+ # Alias for makemigrations
75
85
alias mm := makemigrations
76
86
87
+ # Generate Django migrations
77
88
makemigrations *APPS:
78
89
@just manage makemigrations {% raw %} {{ APPS }}{% endraw %}
79
90
91
+ # Run Django migrations
80
92
migrate *ARGS:
81
93
@just manage migrate {% raw %} {{ ARGS }}{% endraw %}
82
94
95
+ # Open a Django shell using django-extensions shell_plus command
83
96
shell-plus:
84
97
@just manage shell_plus
85
98
99
+ # Quickly create a superuser with the provided credentials
86
100
createsuperuser USERNAME="admin" EMAIL="" PASSWORD="admin":
87
101
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'
88
102
103
+ # Reset a user's password
89
104
resetuserpassword USERNAME="admin" PASSWORD="admin":
90
105
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'
91
106
92
- # ----------------------------------------------------------------------
93
- # DOCS
94
- # ----------------------------------------------------------------------
95
-
96
- _cog:
97
- cog -r docs/just.md
98
-
107
+ # Graph models using django-extensions graph_models command
99
108
graph:
100
109
just manage graph_models users \
101
110
--exclude-models AbstractUser \
102
111
--group-models \
103
112
--output ./docs/applications/images/users.svg
104
113
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
+ # ----------------------------------------------------------------------
107
117
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 %}
110
122
123
+ # Install documentation dependencies
111
124
docs-install:
112
125
python -m uv pip install --upgrade -r docs/requirements.txt
113
126
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
114
132
docs-serve:
115
133
#!/usr/bin/env sh
116
134
just _cog
@@ -120,21 +138,24 @@ docs-serve:
120
138
sphinx-autobuild docs docs/_build/html --host "localhost"
121
139
fi
122
140
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
126
147
127
148
# ----------------------------------------------------------------------
128
149
# DOCKER
129
150
# ----------------------------------------------------------------------
130
151
131
- # Build services using docker- compose
152
+ # Build services using docker compose
132
153
build *ARGS:
133
154
docker compose build {% raw %} {{ ARGS }}{% endraw %}
134
155
135
- # Build production stack using docker- compose
156
+ # Build production stack using docker compose
136
157
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
138
159
139
160
# Stop and remove all containers, networks, images, and volumes
140
161
clean:
@@ -148,7 +169,7 @@ command *ARGS:
148
169
console:
149
170
docker compose run --rm --no-deps app /bin/bash
150
171
151
- # Stop and remove all containers defined in docker- compose
172
+ # Stop and remove all containers defined in docker compose
152
173
down *ARGS:
153
174
docker compose down {% raw %} {{ ARGS }}{% endraw %}
154
175
@@ -160,7 +181,7 @@ logs *ARGS:
160
181
ps:
161
182
docker compose ps
162
183
163
- # Pull the latest versions of all images defined in docker- compose
184
+ # Pull the latest versions of all images defined in docker compose
164
185
pull:
165
186
docker compose pull
166
187
@@ -176,11 +197,11 @@ shell *ARGS="app":
176
197
shell-db:
177
198
docker compose run --rm --no-deps db psql -d {% raw %} {{ DATABASE_URL }}{% endraw %}
178
199
179
- # Start services using docker- compose, defaulting to detached mode
200
+ # Start services using docker compose, defaulting to detached mode
180
201
start *ARGS="--detach":
181
202
@just up {% raw %} {{ ARGS }}{% endraw %}
182
203
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
184
205
start-prod *ARGS="--detach":
185
206
@just up-prod {% raw %} {{ ARGS }}{% endraw %}
186
207
@@ -192,20 +213,20 @@ stop:
192
213
tail *ARGS:
193
214
@just logs '--follow {% raw %} {{ ARGS }}{% endraw %} '
194
215
195
- # Start services using docker- compose, with optional arguments
216
+ # Start services using docker compose, with optional arguments
196
217
up *ARGS:
197
218
docker compose up {% raw %} {{ ARGS }}{% endraw %}
198
219
199
- # Start the full production stack using docker- compose
220
+ # Start the full production stack using docker compose
200
221
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 %}
202
223
203
224
204
225
# ----------------------------------------------------------------------
205
226
# POSTGRES BACKUP AND RESTORE
206
227
# ----------------------------------------------------------------------
207
228
208
- # dump our local database to file
229
+ # Dump our local database to file
209
230
pg_dump database_url=DATABASE_URL file='db.dump':
210
231
docker compose run \
211
232
--rm \
@@ -217,12 +238,12 @@ pg_dump database_url=DATABASE_URL file='db.dump':
217
238
--format=c \
218
239
--verbose
219
240
220
- # dump our production database to file
241
+ # Dump our production database to file
221
242
pg_dump_prod file='production.dump':
222
243
set PROD_DATABASE_URL := "{% raw %} {{ env_var('PROD_DATABASE_URL') }}{% endraw %} "
223
244
@just pg_dump ${PROD_DATABASE_URL} {% raw %} {{ file }}{% endraw %}
224
245
225
- # restore database backup to our local database
246
+ # Restore database backup to our local database
226
247
pg_restore file='db.dump':
227
248
docker compose run \
228
249
--rm \
@@ -240,6 +261,7 @@ pg_restore file='db.dump':
240
261
# UTILS
241
262
# ----------------------------------------------------------------------
242
263
264
+ # Sync .env* files
243
265
envsync:
244
266
#!/usr/bin/env python
245
267
from pathlib import Path
@@ -257,26 +279,34 @@ envsync:
257
279
lines.sort()
258
280
envfile_example.write_text(''.join(lines))
259
281
260
- # format justfile
282
+ # Format justfile
261
283
fmt:
262
284
just --fmt --unstable
263
285
264
- # run pre-commit on all files
286
+ # Run pre-commit on all files
265
287
lint:
266
288
pre-commit run --all-files
267
289
268
290
# ----------------------------------------------------------------------
269
291
# COPIER
270
292
# ----------------------------------------------------------------------
271
293
272
- # create a copier answers file
294
+ # Create a copier answers file
273
295
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
275
305
276
- # update the project using a copier answers file
306
+ # Update the project using a copier answers file
277
307
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 %}
279
309
280
- # loop through all answers files and update the project using copier
310
+ # Loop through all answers files and update the project using copier
281
311
@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