-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a --command argument, allowing to directly call a Django command … #30
base: main
Are you sure you want to change the base?
Conversation
…when databases are ready, without patching the command itself and without loading the django machinery twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I like the idea of the command argument.
There are a few things missing only, to make the change complete. Can you please:
- Add tests for the new CLI option
- Explain the command argument in the README
command_list = shlex.split(command) | ||
call_command(command_list[0], *command_list[1:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit cryptic for one-time readers. Maybe better like this?
command_list = shlex.split(command) | |
call_command(command_list[0], *command_list[1:]) | |
parts = shlex.split(command) | |
executable, params = parts[0], parts[1:] | |
call_command(executable, *params) |
…when databases are ready, without patching the command itself and without loading the django machinery twice.
done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, very nice! 👍
Please, address the remaining comments and the linter complaints.
Please, also add an explanation sentence to the "Use with Your Own Command" section in the README, so that it reads like e.g.
You can use the
-c
option to immediately execute Django management commands once the database is available.Alternatively, ...
Finally, please squash your commits and use a short commit message, and optionally a longer text only afterwards (separated by a blank line).
Then we're ready to merge and I'll happily issue a new release. 🚀
@@ -88,13 +90,20 @@ def add_arguments(self, parser): | |||
help='which database of `settings.DATABASES` ' | |||
'to wait for. Defaults to the "default" ' | |||
'database.') | |||
parser.add_argument("--command", "-c", default=[], | |||
action="append", dest='command', | |||
help='execute this command when database is up (can be repeated multiple times).') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help='execute this command when database is up (can be repeated multiple times).') | |
help='execute this management command when database is up (can be repeated multiple times).') |
@@ -109,3 +109,6 @@ if needed: | |||
delay between checks when database is up (seconds), default: ``1`` | |||
:--database: | |||
which database of ``settings.DATABASES`` to wait for, default: ``default`` | |||
:--command, -c: | |||
execute this Django command when the database is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execute this Django command when the database is ready. | |
execute this Django management command when the database is ready. |
@@ -109,3 +109,6 @@ if needed: | |||
delay between checks when database is up (seconds), default: ``1`` | |||
:--database: | |||
which database of ``settings.DATABASES`` to wait for, default: ``default`` | |||
:--command, -c: | |||
execute this Django command when the database is ready. | |||
This option can be used multiple times: ``wait_for_database -c 'migrate' -c 'runserver --skip-checks'`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option can be used multiple times: ``wait_for_database -c 'migrate' -c 'runserver --skip-checks'`` | |
This option can be used multiple times, e.g. ``wait_for_database -c 'migrate' -c 'runserver --skip-checks'`` |
…when databases are ready, without patching the command itself and without loading the django machinery twice.