Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

d9pouces
Copy link

@d9pouces d9pouces commented Oct 8, 2023

…when databases are ready, without patching the command itself and without loading the django machinery twice.

…when databases are ready, without patching the command itself and without loading the django machinery twice.
Copy link
Member

@bittner bittner left a 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

Comment on lines +108 to +109
command_list = shlex.split(command)
call_command(command_list[0], *command_list[1:])
Copy link
Member

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?

Suggested change
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.
@d9pouces
Copy link
Author

done.
Multiple commands can be called (e.g. migrate then runserver)

Copy link
Member

@bittner bittner left a 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).')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants