From 8c919966894e595b4a173e6019dbbd7e03aa08a2 Mon Sep 17 00:00:00 2001 From: "Thomas Neep (Advanced Research Computing)" Date: Wed, 25 Feb 2026 16:27:10 +0000 Subject: [PATCH 1/2] Try rejigging settings files --- .github/workflows/ci-django-tests.yml | 3 +- agate/core/{settings.py => base_settings.py} | 35 ++++++-------------- agate/core/local_settings.test.py | 9 +++-- agate/manage.py | 2 +- 4 files changed, 19 insertions(+), 30 deletions(-) rename agate/core/{settings.py => base_settings.py} (84%) diff --git a/.github/workflows/ci-django-tests.yml b/.github/workflows/ci-django-tests.yml index 9b547c5..7a7fc2a 100644 --- a/.github/workflows/ci-django-tests.yml +++ b/.github/workflows/ci-django-tests.yml @@ -25,6 +25,5 @@ jobs: - name: Run Tests run: | cd agate - mv core/local_settings.test.py core/local_settings.py - coverage run manage.py test + coverage run manage.py test --settings=local_settings.test.py coverage report diff --git a/agate/core/settings.py b/agate/core/base_settings.py similarity index 84% rename from agate/core/settings.py rename to agate/core/base_settings.py index f1d4764..8dcf84c 100644 --- a/agate/core/settings.py +++ b/agate/core/base_settings.py @@ -5,9 +5,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_DIR = os.path.join(BASE_DIR, 'core/templates') - # Application definition - INSTALLED_APPS = [ # Django default apps 'django.contrib.admin', @@ -110,18 +108,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -# Import local_settings.py -SECRET_KEY = None -try: - from .local_settings import * # NOQA -except ImportError: - sys.exit('Unable to import local_settings.py (refer to local_settings.example.py for help)') - -# Ensure the SECRET_KEY is supplied in local_settings.py - and trust that the other settings are there too. -if not SECRET_KEY: # NOQA - sys.exit('Missing SECRET_KEY in local_settings.py') - - # Storages # Default STORAGES from Django documentation @@ -131,13 +117,7 @@ "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}, } -# Use ManifestStaticFilesStorage when not in debug mode -if not DEBUG: # NOQA - STORAGES['staticfiles'] = {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"} - - # Logging - LOGGING = { 'version': 1, 'disable_existing_loggers': False, @@ -160,9 +140,16 @@ }, }, 'handlers': { - 'stream': { + 'stream_debug': { + 'class': 'logging.StreamHandler', + 'filters': ['require_debug_true'], + 'level': 'DEBUG', # NOQA + 'formatter': 'verbose', + }, + 'stream_prod': { 'class': 'logging.StreamHandler', - 'level': 'DEBUG' if DEBUG else 'INFO', # NOQA + 'filters': ['require_debug_false'], + 'level': os.getenv("DJANGO_LOG_LEVEL", "INFO"), # NOQA 'formatter': 'verbose', }, 'file': { @@ -181,8 +168,8 @@ }, 'loggers': { 'django': { - 'handlers': ['stream', 'file', 'mail_admins'], - 'level': 'DEBUG' if DEBUG else 'INFO', # NOQA + 'handlers': ['stream_debug', 'stream_prod', 'file', 'mail_admins'], + 'level': 'DEBUG', # NOQA 'propagate': 'True', }, }, diff --git a/agate/core/local_settings.test.py b/agate/core/local_settings.test.py index a34de82..44d375b 100644 --- a/agate/core/local_settings.test.py +++ b/agate/core/local_settings.test.py @@ -7,8 +7,7 @@ import os from empty_message_retrieval import EmptyMessageRetrieval - -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +from .base_settings import * SECRET_KEY = 'u6n(9&8g-3=6d1#jyp^#))you-h&y^-5y7*&hu)cpxzeu_7#j+' @@ -16,7 +15,7 @@ ALLOWED_HOSTS = ['*'] -ADMIN_EMAIL = 'bear-rsg@contacts.bham.ac.uk' +# ADMIN_EMAIL = 'bear-rsg@contacts.bham.ac.uk' DATABASES = { 'default': { @@ -33,3 +32,7 @@ MESSAGE_RETRIEVAL = EmptyMessageRetrieval() LIMITED_PROJECT_LIST = ["synthscape"] + +# Use ManifestStaticFilesStorage when not in debug mode +if not DEBUG: # NOQA + STORAGES['staticfiles'] = {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"} diff --git a/agate/manage.py b/agate/manage.py index 52c2189..a0d0781 100644 --- a/agate/manage.py +++ b/agate/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.local_settings') try: from django.core.management import execute_from_command_line except ImportError as exc: From e371d104163bc992e7c5d0426f9ce14de8fb155d Mon Sep 17 00:00:00 2001 From: "Thomas Neep (Advanced Research Computing)" Date: Wed, 25 Feb 2026 16:42:50 +0000 Subject: [PATCH 2/2] Fix CI issues --- .github/workflows/ci-django-tests.yml | 2 +- agate/core/base_settings.py | 1 - agate/core/{local_settings.test.py => local_settings_test.py} | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) rename agate/core/{local_settings.test.py => local_settings_test.py} (92%) diff --git a/.github/workflows/ci-django-tests.yml b/.github/workflows/ci-django-tests.yml index 7a7fc2a..40fb65e 100644 --- a/.github/workflows/ci-django-tests.yml +++ b/.github/workflows/ci-django-tests.yml @@ -25,5 +25,5 @@ jobs: - name: Run Tests run: | cd agate - coverage run manage.py test --settings=local_settings.test.py + coverage run manage.py test --settings="core.local_settings_test" coverage report diff --git a/agate/core/base_settings.py b/agate/core/base_settings.py index 8dcf84c..c37c493 100644 --- a/agate/core/base_settings.py +++ b/agate/core/base_settings.py @@ -1,5 +1,4 @@ import os -import sys # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/agate/core/local_settings.test.py b/agate/core/local_settings_test.py similarity index 92% rename from agate/core/local_settings.test.py rename to agate/core/local_settings_test.py index 44d375b..1c7cf8d 100644 --- a/agate/core/local_settings.test.py +++ b/agate/core/local_settings_test.py @@ -7,7 +7,9 @@ import os from empty_message_retrieval import EmptyMessageRetrieval -from .base_settings import * + +from .base_settings import * # noqa: F403 +from .base_settings import BASE_DIR, STORAGES SECRET_KEY = 'u6n(9&8g-3=6d1#jyp^#))you-h&y^-5y7*&hu)cpxzeu_7#j+'