From ee72ed8abbd005794b6624c26a39a927c0580901 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Tue, 26 Nov 2024 09:31:59 +0300 Subject: [PATCH 1/5] Add minimal project description --- pyproject.toml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8131b28c..40b1db8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,27 @@ [project] +name = "commons-api" +version = "0.0.0" requires-python = ">= 3.11" +authors = [{ name = 'Code for Africa', email = 'tech@codeforafrica.org' }] +readme = "README.md" +keywords = ["api", "commons", "civictech", "trolltracker"] +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Programming Language :: Python', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.11', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Framework :: Django', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Internet', +] + +[project.urls] +Repository = "https://github.com/CodeForAfrica/api" +Issues = "https://github.com/CodeForAfrica/api/issues" [tool.isort] profile = "black" @@ -8,8 +30,5 @@ profile = "black" ignore_missing_imports = true # TODO(kilemensi): mypy django stubs -[tool.ruff] -target-version = "py311" # default: py39 - [tool.setuptools_scm] write_to = "VERSION" From b11e233ea58d75e197b0bed5bf56589ea6b8dd19 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Tue, 26 Nov 2024 09:32:20 +0300 Subject: [PATCH 2/5] Update yamllint config and format --- .yamllint.yaml | 5 ++- compose.yaml | 111 +++++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/.yamllint.yaml b/.yamllint.yaml index 742192b9..1b087785 100644 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -1,9 +1,12 @@ extends: default rules: + # https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.brackets + brackets: + max-spaces-inside: 1 # https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.line_length line-length: - max: 88 # profile=black + max: 88 # profile=black # https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_start document-start: present: false diff --git a/compose.yaml b/compose.yaml index 5cda4375..6144ff21 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,62 +1,63 @@ services: - db: - image: postgres:13.4 - restart: unless-stopped - volumes: - - db-data:/var/lib/postgresql/data/ - environment: - - POSTGRES_USER=${PGUSER:-api} - - POSTGRES_PASSWORD=${PGPASSWORD:-api} - - POSTGRES_DB=${PGDATABASE:-api} - ports: - # Allow DB access from outside the container - - "54321:5432" - healthcheck: - test: ["CMD-SHELL", "pg_isready -U twoops_tracker"] - interval: 5s - timeout: 5s - retries: 5 + db: + image: postgres:13.4 + restart: unless-stopped + volumes: + - db-data:/var/lib/postgresql/data/ + environment: + - POSTGRES_USER=${PGUSER:-api} + - POSTGRES_PASSWORD=${PGPASSWORD:-api} + - POSTGRES_DB=${PGDATABASE:-api} + ports: + # Allow DB access from outside the container + - "54321:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U twoops_tracker"] + interval: 5s + timeout: 5s + retries: 5 - redis: - restart: always - image: redis:6.2 - ports: - # Allow Redis access from outside the container - - "63791:6379" + redis: + restart: always + image: redis:6.2 + ports: + # Allow Redis access from outside the container + - "63791:6379" - twoopstracker_app: - image: codeforafrica/twoopstracker:latest - depends_on: - - db - - redis - env_file: - - ./twoops_tracker/.env.template - volumes: - - app-media:/app/media - - app-staticfiles:/app/staticfiles + twoopstracker_app: + image: codeforafrica/twoopstracker:latest + platform: "linux/amd64" + depends_on: + - db + - redis + env_file: + - ./twoops_tracker/.env.template + volumes: + - app-media:/app/media + - app-staticfiles:/app/staticfiles - twoopstracker: - image: nginx:1.20 - restart: unless-stopped - volumes: - - ./contrib/docker-compose/nginx:/etc/nginx/conf.d - - app-media:/var/www/media - - app-staticfiles:/var/www/static - ports: - - 8000:80 - depends_on: - - twoopstracker_app + twoopstracker: + image: nginx:1.20 + restart: unless-stopped + volumes: + - ./contrib/docker-compose/nginx:/etc/nginx/conf.d + - app-media:/var/www/media + - app-staticfiles:/var/www/static + ports: + - 8000:80 + depends_on: + - twoopstracker_app - pesacheck_meedan_bridge: - image: codeforafrica/pesacheck_meedan_bridge:latest - command: ["tail", "-f", "/dev/null"] - volumes: - - pesacheck-data:/app/database - env_file: - - ./pesacheck_meedan_bridge/.env + pesacheck_meedan_bridge: + image: codeforafrica/pesacheck_meedan_bridge:latest + command: [ "tail", "-f", "/dev/null" ] + volumes: + - pesacheck-data:/app/database + env_file: + - ./pesacheck_meedan_bridge/.env volumes: - app-media: - app-staticfiles: - db-data: - pesacheck-data: + app-media: + app-staticfiles: + db-data: + pesacheck-data: From 866825bed79350a55c3d70499da52fb40cd79712 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Tue, 26 Nov 2024 09:32:53 +0300 Subject: [PATCH 3/5] Upgrade Django and other deps --- 3rdparty/py/requirements-all.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/3rdparty/py/requirements-all.txt b/3rdparty/py/requirements-all.txt index 98d38891..cea6e1f8 100644 --- a/3rdparty/py/requirements-all.txt +++ b/3rdparty/py/requirements-all.txt @@ -1,15 +1,15 @@ -boto3==1.35.64 +boto3==1.35.68 celery==5.4.0 -dj-rest-auth==5.1.0 -# Match dj-rest-auth[with_social]==5.1.0 +dj-rest-auth==7.0.0 +# Must match dj-rest-auth[with_social]==7.0.0 django-allauth>=0.56.0,<0.62.0 -Django==3.2.23 -django-cors-headers==4.5.0 +Django==4.2.16 +django-cors-headers==4.6.0 django-storages==1.14.4 -djangorestframework==3.15.1 +djangorestframework==3.15.2 djangorestframework-simplejwt==5.3.1 -environs[django]==10.3.0 -google-api-python-client==2.153.0 +environs[django]==11.2.1 +google-api-python-client==2.154.0 google-auth==2.36.0 google-auth-httplib2==0.2.0 google-auth-oauthlib==1.2.1 @@ -19,7 +19,7 @@ html2text==2024.2.26 lxml==5.3.0 redis==5.2.0 requests==2.32.3 -sentry-sdk==2.18.0 +sentry-sdk==2.19.0 tablib[xlsx]==3.7.0 trafilatura==1.12.2 -tweepy==4.14.0 +tweepy==4.13.0 # NOTE(kilemensi) >=4.14.0 introduces breaking changes! From c927e04f11cd9ad4f0bd4857f6e9c87416ae3b6f Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Tue, 26 Nov 2024 09:33:34 +0300 Subject: [PATCH 4/5] Upgrade code to work with Django 4.2 --- twoops_tracker/py/twoopstracker/settings.py | 1 + twoops_tracker/py/twoopstracker/twoops/models.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/twoops_tracker/py/twoopstracker/settings.py b/twoops_tracker/py/twoopstracker/settings.py index f35e9d67..0af139a4 100644 --- a/twoops_tracker/py/twoopstracker/settings.py +++ b/twoops_tracker/py/twoopstracker/settings.py @@ -89,6 +89,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "allauth.account.middleware.AccountMiddleware", ] ROOT_URLCONF = "twoopstracker.urls" diff --git a/twoops_tracker/py/twoopstracker/twoops/models.py b/twoops_tracker/py/twoopstracker/twoops/models.py index d6c06b02..3702e7e7 100644 --- a/twoops_tracker/py/twoopstracker/twoops/models.py +++ b/twoops_tracker/py/twoopstracker/twoops/models.py @@ -1,6 +1,6 @@ from django.conf import settings from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from twoopstracker.db.models import TimestampedModelMixin From d60fbb169a913c00cc6e3f0bd2c5a57be7dc982c Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Tue, 26 Nov 2024 09:58:28 +0300 Subject: [PATCH 5/5] Specify which main.py --- twoops_tracker/py/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twoops_tracker/py/BUILD b/twoops_tracker/py/BUILD index ae7c1515..fcbc46d2 100644 --- a/twoops_tracker/py/BUILD +++ b/twoops_tracker/py/BUILD @@ -54,5 +54,5 @@ pex_binary( dependencies=[ ":lib", ], - entry_point="main.py", + entry_point="twoops_tracker/py/twoopstracker/main", )