From 9354414386c4ecf6d293e800a9c5a6cc50cdb95a Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Sat, 6 Jun 2020 00:52:50 +0200 Subject: [PATCH] Move manage.py entrypoint to its own function --- manage.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/manage.py b/manage.py index e9e7fdde0f..ab42d843e6 100755 --- a/manage.py +++ b/manage.py @@ -2,14 +2,19 @@ import os import sys -if __name__ == "__main__": +try: + from django.core.management import execute_from_command_line +except ImportError as exc: + raise ImportError( + "Couldn't import Django. " + "Run `poetry shell` to activate a virtual environment first." + ) from exc + + +def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main()