Bring these in line with modern Django

This commit is contained in:
Joel Falknau 2025-03-26 13:19:25 +10:00
parent 75d67aa1b1
commit 7ba1699dc6
No known key found for this signature in database
2 changed files with 32 additions and 30 deletions

View File

@ -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:
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 err
raise
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -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:
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 err # Provide context for the original error
raise # Re-raise original exception with context
) from exc
execute_from_command_line(sys.argv.insert(1, "test"))
if __name__ == '__main__':
main()