Skip to content

Commit ad9ce06

Browse files
authored
Merge pull request #14 from bckohan/v1.1.x
V1.1.x
2 parents f6c169f + dd3b464 commit ad9ce06

File tree

18 files changed

+993
-3060
lines changed

18 files changed

+993
-3060
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,7 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162-
**/.DS_Store
162+
**/.DS_Store
163+
**/track.json
164+
poetry.lock
165+

README.md

+26-16
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@
1313
[![Lint Status](https://github.com/bckohan/django-routines/workflows/lint/badge.svg)](https://github.com/bckohan/django-routines/actions/workflows/lint.yml)
1414

1515

16-
Configure batches of Django management commands in your settings files and run them all at once.
17-
For example, batch together your common database maintenance tasks, deployment routines or any
18-
other set of commands you need to run together. This helps single source general site maintenance
19-
into your settings files keeping your code base [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself).
16+
Configure batches of Django management commands in your settings files and run them all at once. For example, batch together your common database maintenance tasks, deployment routines or any other set of commands you need to run together. This helps single source general site maintenance into your settings files keeping your code base [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself).
2017

2118
## Example
2219

23-
Let's define two named routines, "package" and "deploy". The package routine will be a collection
24-
of commands that we typically run to generate package artifacts (like migrations and transpiled
25-
javascript). The deploy routine will be a collection of commands we typically run when deploying
26-
the site for the first time on a new server or when we deploy version updates on the server.
20+
Let's define two named routines, "package" and "deploy". The package routine will be a collection of commands that we typically run to generate package artifacts (like migrations and transpiled javascript). The deploy routine will be a collection of commands we typically run when deploying the site for the first time on a new server or when we deploy version updates on the server.
2721

2822
**Routine commands are run in the order they are registered, or by [priority](#priorities).**
2923

24+
There are two types of commands, management commands and system commands. The management commands will be called in the same process space as routine unless --subprocess is specified in which case they will use the same management script as routine was invoked with or whatever value you supply to --manage-script. System commands are always invoked as subprocesses.
25+
3026
In our settings file we may define these routines like this:
3127

3228
```python
33-
from django_routines import RoutineCommand, command, routine
29+
from django_routines import (
30+
ManagementCommand,
31+
SystemCommand,
32+
command,
33+
system,
34+
routine
35+
)
3436

3537
# register routines and their help text
3638
routine(
@@ -43,19 +45,21 @@ routine(
4345
# you may register commands on a routine after defining a routine (or before!)
4446
command("package", "makemigrations")
4547
command("package", "renderstatic")
48+
system("package", "poetry", "build")
4649

4750
routine(
4851
"deploy",
4952
"Deploy the site application into production.",
5053

51-
# you may also specify commands inline using the RoutineCommand dataclass
52-
RoutineCommand(
54+
# you may also specify commands inline using the ManagementCommand dataclass
55+
ManagementCommand(
5356
("routine", "package"), switches=["prepare"]
5457
), # routine commands can be other routines!
55-
RoutineCommand("migrate"),
56-
RoutineCommand("collectstatic"),
57-
RoutineCommand(("shellcompletion", "install"), switches=["initial"]),
58-
RoutineCommand(("loaddata", "./fixtures/demo.json"), switches=["demo"]),
58+
ManagementCommand("migrate"),
59+
ManagementCommand("collectstatic"),
60+
ManagementCommand(("shellcompletion", "install"), switches=["initial"]),
61+
ManagementCommand(("loaddata", "./fixtures/demo.json"), switches=["demo"]),
62+
SystemCommand(("touch", "/path/to/wsgi.py")),
5963

6064
# define switches that toggle commands on and off
6165
prepare="Generate artifacts like migrations and transpiled javascript.",
@@ -98,7 +102,7 @@ For example to deploy our demo on a new server we would run:
98102

99103
## Settings
100104

101-
The [RoutineCommand](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.RoutineCommand) dataclass, [routine](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.routine) and [command](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.command) helper functions in the example above make it easier for us to work with the native configuration format which is a dictionary structure defined in the ``DJANGO_ROUTINES`` setting attribute. For example the above configuration is equivalent to:
105+
The [ManagementCommand](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.ManagementCommand) dataclass, [routine](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.routine) and [command](https://django-routines.readthedocs.io/en/latest/reference.html#django_routines.command) helper functions in the example above make it easier for us to work with the native configuration format which is a dictionary structure defined in the ``DJANGO_ROUTINES`` setting attribute. For example the above configuration is equivalent to:
102106

103107
```python
104108
DJANGO_ROUTINES = {
@@ -115,6 +119,7 @@ DJANGO_ROUTINES = {
115119
"command": ("loaddata", "./fixtures/demo.json"),
116120
"switches": ["demo"],
117121
},
122+
{"command": ("touch", "/path/to/wsgi.py"), "kind": "system"},
118123
],
119124
"help_text": "Deploy the site application into production.",
120125
"name": "deploy",
@@ -130,6 +135,7 @@ DJANGO_ROUTINES = {
130135
"commands": [
131136
{"command": "makemigrations"},
132137
{"command": "renderstatic"},
138+
{"command": ("poetry", "build"), "kind": "system"},
133139
],
134140
"help_text": "Generate pre-package artifacts like migrations and "
135141
"transpiled javascript.",
@@ -186,3 +192,7 @@ When specifying arguments you may add them to the command tuple OR specify them
186192
```
187193

188194
*You only need to install [django_typer](https://github.com/bckohan/django-typer) as an app if you want to use the shellcompletion command to [enable tab-completion](https://django-typer.readthedocs.io/en/latest/shell_completion.html) or if you would like django-typer to install [rich traceback rendering](https://django-typer.readthedocs.io/en/latest/howto.html#configure-rich-stack-traces) for you - which it does by default if rich is also installed.*
195+
196+
## Rationale
197+
198+
When does it make sense to configure routines in Django settings? Its generally convenient to group common management pathways into easily discoverable and executable aggregations of subroutines. This is usually done in supporting shell scripts or just files and in most cases that is appropriate. If your goal is to keep your Django deployment as tight and self contained as possible and the deployment is not generally very complex, using django-routines can make a lot of sense. It can eliminate extra dependencies on a shell scripting environment or just files and can keep this logic packaged with your installable wheel.

0 commit comments

Comments
 (0)