diff --git a/allianceauth/project_template/manage.py b/allianceauth/project_template/manage.py index acf38748..17c685cf 100644 --- a/allianceauth/project_template/manage.py +++ b/allianceauth/project_template/manage.py @@ -1,22 +1,22 @@ #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" import os import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name}}.settings.local") + +def main() -> None: + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings') try: from django.core.management import execute_from_command_line - except ImportError as err: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django # noqa: F401 - except ImportError: - 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 err - raise + 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() diff --git a/runtests.py b/runtests.py index 7aadd287..6e67ae50 100644 --- a/runtests.py +++ b/runtests.py @@ -1,21 +1,23 @@ #!/usr/bin/env python +""" +Django's command-line utility for administrative tasks. +Modified to insert Tests as the first argument +""" import sys -if __name__ == "__main__": + +def main() -> None: + """Run tests""" try: from django.core.management import execute_from_command_line - except ImportError as err: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django # noqa: F401 - except ImportError: - 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 err # Provide context for the original error - raise # Re-raise original exception with context - + 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.insert(1, "test")) + + +if __name__ == '__main__': + main()