From a3bd64e2542ed3798f1440913cbd6542eabb4a8d Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Mon, 31 Mar 2025 17:11:07 -0700 Subject: [PATCH 01/12] Upgraded Python to v3.11.8 --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 32a8d83a..cf3b8042 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.7.8 +python-3.11.8 From 2071b9d9ff2e93a5fcbd89ec1d6df9079c00cd4e Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Mon, 31 Mar 2025 17:18:43 -0700 Subject: [PATCH 02/12] update GitHub Actions --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5da284c3..b4231731 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,10 +28,10 @@ jobs: SECRET_KEY: BetPHpGoUXUwjaAXm6ArIhV95xLdDZtu8QEGnNXY3eTknIkD AUTH_STAFF_EMAIL_DOMAINS: mozillafoundation.org steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.11 - name: Install Python Dependencies run: | pip install -r requirements.txt -r dev-requirements.txt From 4b660be56a1368ea81453ec4292f8b9eb5a1ca87 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:39:05 -0700 Subject: [PATCH 03/12] Pin setuptools and regenerate requirements.txt for Python 3.11 --- requirements.in | 1 + requirements.txt | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.in b/requirements.in index a4b75fd5..b393aae3 100644 --- a/requirements.in +++ b/requirements.in @@ -19,4 +19,5 @@ Pillow==8.3.2 protobuf==3.12.2 psycopg2-binary requests +setuptools==65.5.1 whitenoise diff --git a/requirements.txt b/requirements.txt index a5b586c5..517c3969 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ # -# This file is autogenerated by pip-compile with python 3.9 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: # -# pip-compile +# pip-compile requirements.in # boto3==1.16.26 # via -r requirements.in From c4c1c567d3c209cdc579cd678b93533ceb9238f3 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:43:39 -0700 Subject: [PATCH 04/12] pin setuptools in CI to fix django-allauth build issue --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4231731..f1fc11f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,10 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.11 + # setuptools >=66 removed `convert_path`, which breaks django-allauth 0.48.0 + # See https://github.com/pypa/setuptools/issues/3772 + - name: Install setuptools 65.5.1 for compatibility with django-allauth + run: pip install "setuptools==65.5.1" - name: Install Python Dependencies run: | pip install -r requirements.txt -r dev-requirements.txt From b43b967935bbe3ed63dd178eb0fc69b409110215 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:47:12 -0700 Subject: [PATCH 05/12] fix CI - disable build isolation and pin setuptools for django-allauth --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1fc11f3..ae5b86c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,9 @@ jobs: # See https://github.com/pypa/setuptools/issues/3772 - name: Install setuptools 65.5.1 for compatibility with django-allauth run: pip install "setuptools==65.5.1" - - name: Install Python Dependencies + - name: Install Python Dependencies (no build isolation) run: | - pip install -r requirements.txt -r dev-requirements.txt + pip install --no-build-isolation -r requirements.txt -r dev-requirements.txt python manage.py migrate - name: Run Tests run: | From 50216b3ac47fe248db46478a84d3af046c15d66b Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:49:32 -0700 Subject: [PATCH 06/12] fix CI - add wheel and disable build isolation for setuptools compatibility --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae5b86c5..072e3acc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,8 @@ jobs: # See https://github.com/pypa/setuptools/issues/3772 - name: Install setuptools 65.5.1 for compatibility with django-allauth run: pip install "setuptools==65.5.1" + - name: Install wheel for building packages like cffi + run: pip install wheel - name: Install Python Dependencies (no build isolation) run: | pip install --no-build-isolation -r requirements.txt -r dev-requirements.txt From ac7d5123c78c71cb2f00caa94de41f87eeced787 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:53:50 -0700 Subject: [PATCH 07/12] fix CI - install system dependencies for Pillow (libjpeg-dev, zlib1g-dev) --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 072e3acc..1802846b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,11 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.11 + # Pillow requires libjpeg-dev, zlib1g-dev, etc. to build from source + - name: Install system dependencies for Pillow build + run: | + sudo apt-get update + sudo apt-get install -y libjpeg-dev zlib1g-dev libpng-dev # setuptools >=66 removed `convert_path`, which breaks django-allauth 0.48.0 # See https://github.com/pypa/setuptools/issues/3772 - name: Install setuptools 65.5.1 for compatibility with django-allauth From eaf05f3290b33d01b18f8640c72aa7cc362410f2 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 00:59:25 -0700 Subject: [PATCH 08/12] fix CI - pin psycopg2 to a compatible version --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1802846b..6f85ef96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: run: pip install wheel - name: Install Python Dependencies (no build isolation) run: | + pip install "psycopg2<3" # Pin psycopg2 to a compatible version pip install --no-build-isolation -r requirements.txt -r dev-requirements.txt python manage.py migrate - name: Run Tests From 516c9b6d04604cbd0f293fa9469edc3bffc2ea62 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 01:11:24 -0700 Subject: [PATCH 09/12] fix CI - remove psycopg2 pin as psycopg2-binary installs cleanly on 3.11 --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f85ef96..1802846b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,6 @@ jobs: run: pip install wheel - name: Install Python Dependencies (no build isolation) run: | - pip install "psycopg2<3" # Pin psycopg2 to a compatible version pip install --no-build-isolation -r requirements.txt -r dev-requirements.txt python manage.py migrate - name: Run Tests From b059d5d5afe477c3a59bf8ee2a2bed599a174ecd Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 01:21:47 -0700 Subject: [PATCH 10/12] fix CI - add .env file with DATABASE_URL so Django uses Postgres instead of default SQLite By default, Django falls back to SQLite when no DATABASE_URL is set in the environment. This was causing the test suite to fail in CI despite the Postgres service being available. This commit creates a fake .env file in CI with the correct DATABASE_URL so that dj-database-url can correctly configure Django to connect to the CI's Postgres service. --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1802846b..a0c8ac59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,9 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.11 + - name: Write .env file with DATABASE_URL for CI + run: | + echo "DATABASE_URL=postgres://postgres:postgres@localhost:5432/pulseapi" > .env # Pillow requires libjpeg-dev, zlib1g-dev, etc. to build from source - name: Install system dependencies for Pillow build run: | From 2ea4030cb441706b82290daca1acdb16e6f90da0 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 01:32:26 -0700 Subject: [PATCH 11/12] refactor settings to use DATABASE_URL if available, fallback to SQLite This updates the database configuration to first check for a DATABASE_URL environment variable, allowing seamless support for PostgreSQL in CI and production. If DATABASE_URL is not set, it defaults to using SQLite, which is more convenient for local development. --- pulseapi/settings.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pulseapi/settings.py b/pulseapi/settings.py index c339adb5..ceb4c878 100644 --- a/pulseapi/settings.py +++ b/pulseapi/settings.py @@ -240,17 +240,25 @@ def show_toolbar(request): # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - +# Try to get DATABASE_URL from the environment (e.g. .env file or CI env vars) DATABASE_URL = env('DATABASE_URL') -if DATABASE_URL is not None: - DATABASES['default'].update(dj_database_url.config()) +if DATABASE_URL: + # If DATABASE_URL is provided, use it to configure the default database + # This will typically be a Postgres database in production or CI + DATABASES = { + 'default': dj_database_url.parse(DATABASE_URL) + } +else: + # If DATABASE_URL is not set, fall back to using SQLite + # This is a good default for local development environments + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } + } + # Password validation From 7885949ab06694ab2db1bae8f25a8fbfc299e2a0 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 1 Apr 2025 01:38:57 -0700 Subject: [PATCH 12/12] =?UTF-8?q?fix=20CI=20=E2=80=93=20build=20psycopg2-b?= =?UTF-8?q?inary=20from=20source=20for=20Python=203.11=20compatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0c8ac59..895e88b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: run: pip install wheel - name: Install Python Dependencies (no build isolation) run: | + pip install --no-binary psycopg2-binary psycopg2-binary pip install --no-build-isolation -r requirements.txt -r dev-requirements.txt python manage.py migrate - name: Run Tests