Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mise à jour de Python vers 3.12 [GEN-2214] #5049

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
cache: pip
cache-dependency-path: requirements/test.txt
- name: 💾 Restore static files cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mkchangelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
- name: 📥 Generate changelog
run: scripts/mkchangelog --publish
env:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/review-app-creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ jobs:
# but we want to use the one from c1-deployment-config
$CLEVER_CLI env rm CC_PYTHON_VERSION

- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: 🚀 Deploy to Clever Cloud
timeout-minutes: 15
run: |
Expand Down Expand Up @@ -126,6 +131,11 @@ jobs:
run:
$CLEVER_CLI env set SKIP_FIXTURES true

- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: 🚀 Deploy to Clever Cloud
timeout-minutes: 15
run: scripts/clever-deploy --clever-cli "$CLEVER_CLI" --branch "$BRANCH" --app-alias "$REVIEW_APP_NAME"
2 changes: 1 addition & 1 deletion .github/workflows/review-app-removal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: 🗑 Delete S3 bucket
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Global tasks.
# =============================================================================
PYTHON_VERSION := python3.11
PYTHON_VERSION := python3.12
LINTER_CHECKED_DIRS := config itou scripts tests
PGDATABASE ?= itou
REQUIREMENTS_PATH ?= requirements/dev.txt
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ services:
args:
APP_USER: app
APP_DIR: /app
PYTHON_VERSION: 3.11
PYTHON_VERSION: 3.12
PG_MAJOR: 15
volumes:
# Mount the current directory into `/app` inside the running container.
Expand Down
4 changes: 2 additions & 2 deletions itou/emails/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from functools import partial
from itertools import batched

import sentry_sdk
from anymail.exceptions import AnymailError
Expand All @@ -12,7 +13,6 @@
from requests.exceptions import InvalidJSONError

from itou.emails.models import Email
from itou.utils.iterators import chunks


logger = logging.getLogger("itou.emails")
Expand Down Expand Up @@ -44,7 +44,7 @@ def sanitize_mailjet_recipients(email_message):
return [email_message]

sanitized_emails = []
to_chunks = chunks(email_message.to, _MAILJET_MAX_RECIPIENTS)
to_chunks = batched(email_message.to, _MAILJET_MAX_RECIPIENTS)
# We could also combine to, cc and bcc, but it's useless for now

for to_chunk in to_chunks:
Expand Down
4 changes: 2 additions & 2 deletions itou/employee_record/common_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
from io import BytesIO
from itertools import batched

import paramiko
from django.db import transaction
Expand All @@ -12,7 +13,6 @@
from itou.employee_record.serializers import EmployeeRecordSerializer, EmployeeRecordUpdateNotificationSerializer
from itou.utils.asp import REMOTE_DOWNLOAD_DIR, REMOTE_UPLOAD_DIR
from itou.utils.command import BaseCommand
from itou.utils.iterators import chunks


class IgnoreFile(Exception):
Expand Down Expand Up @@ -175,7 +175,7 @@ def preflight(self, object_class):
)

errors = False
for idx, elements in enumerate(chunks(new_objects, EmployeeRecordBatch.MAX_EMPLOYEE_RECORDS), 1):
for idx, elements in enumerate(batched(new_objects, EmployeeRecordBatch.MAX_EMPLOYEE_RECORDS), 1):
# A batch + serializer must be created with notifications for correct serialization
batch = EmployeeRecordBatch(elements)

Expand Down
4 changes: 2 additions & 2 deletions itou/gps/management/commands/import_advisor_information.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from itertools import batched
from math import ceil

from django.db import transaction
Expand All @@ -8,7 +9,6 @@
from itou.users.enums import UserKind
from itou.users.models import JobSeekerProfile, User
from itou.utils.command import BaseCommand
from itou.utils.iterators import chunks


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +48,7 @@ def handle(self, import_excel_file, wet_run=False, **options):
created_rows_count = 0
updated_rows_count = 0

for chunk_idx, chunked_beneficiary_pks in enumerate(chunks(beneficiaries_pks, chunk_size), 1):
for chunk_idx, chunked_beneficiary_pks in enumerate(batched(beneficiaries_pks, chunk_size), 1):
# NOTE: cannot use select_for_update below
# NotSupportedError: FOR UPDATE cannot be applied to the nullable side of an outer join
implicated_profiles = JobSeekerProfile.objects.filter(user_id__in=chunked_beneficiary_pks).select_related(
Expand Down
4 changes: 2 additions & 2 deletions itou/gps/management/commands/init_follow_up_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from itertools import batched

from django.conf import settings
from django.contrib.postgres.aggregates import ArrayAgg
Expand All @@ -10,7 +11,6 @@
from itou.users.enums import UserKind
from itou.users.models import User
from itou.utils.command import BaseCommand
from itou.utils.iterators import chunks


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,7 +55,7 @@ def handle(self, wet_run=False, verbose=False, **options):
logger.info(f"Job applications: {job_applications.count()}.")
logger.info(f"Groups to be created: {len(beneficiaries_without_group_ids)}.")

for beneficiaries_ids in chunks(beneficiaries_without_group_ids, 1000):
for beneficiaries_ids in batched(beneficiaries_without_group_ids, 1000):
job_applications_filters = ~Q(job_applications__sender__kind=UserKind.JOB_SEEKER) & ~Q(
job_applications__state=JobApplicationState.NEW
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import logging
from itertools import batched
from math import ceil

from django.conf import settings
Expand All @@ -15,7 +16,6 @@
from itou.job_applications.models import JobApplication, JobApplicationState, JobApplicationTransitionLog
from itou.users.models import User
from itou.utils.command import BaseCommand
from itou.utils.iterators import chunks


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,7 +51,7 @@ def handle(self, wet_run=False, **options):
chunks_total = ceil(len(beneficiaries_pks) / 1000)

chunks_count = 0
for beneficiaries_ids in chunks(beneficiaries_pks, 1000):
for beneficiaries_ids in batched(beneficiaries_pks, 1000):
beneficiaries_qs = (
User.objects.filter(pk__in=beneficiaries_ids)
.annotate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.6 on 2024-05-31 08:08

import time
from itertools import batched

from django.db import migrations
from django.db.models import Case, DateTimeField, F, OuterRef, Subquery, When
Expand All @@ -9,7 +10,6 @@
from itou.approvals.enums import Origin
from itou.job_applications.enums import JobApplicationState
from itou.job_applications.models import JobApplicationWorkflow
from itou.utils.iterators import chunks


def _fill_accepted_jobapplication_processed_at(apps, schema_editor):
Expand Down Expand Up @@ -56,7 +56,7 @@ def _fill_accepted_jobapplication_processed_at(apps, schema_editor):
count = 0
start = time.perf_counter()
print(f"Updating {len(job_apps_ids)} accepted job applications")
for ids in chunks(job_apps_ids, 10000):
for ids in batched(job_apps_ids, 10000):
job_applications = list(accepted_qs.filter(pk__in=ids))
for job_application in job_applications:
job_application.processed_at = job_application.accepted_at
Expand Down Expand Up @@ -90,7 +90,7 @@ def _fill_refused_jobapplication_processed_at(apps, schema_editor):
count = 0
start = time.perf_counter()
print(f"Updating {len(job_apps_ids)} refused job applications")
for ids in chunks(job_apps_ids, 10000):
for ids in batched(job_apps_ids, 10000):
job_applications = list(refused_qs.filter(pk__in=ids))
for job_application in job_applications:
job_application.processed_at = job_application.refused_at or job_application.updated_at
Expand Down Expand Up @@ -124,7 +124,7 @@ def _fill_cancelled_jobapplication_processed_at(apps, schema_editor):
count = 0
start = time.perf_counter()
print(f"Updating {len(job_apps_ids)} cancelled job applications")
for ids in chunks(job_apps_ids, 10000):
for ids in batched(job_apps_ids, 10000):
job_applications = list(cancelled_qs.filter(pk__in=ids))
for job_application in job_applications:
job_application.processed_at = job_application.cancelled_at or job_application.updated_at
Expand Down Expand Up @@ -158,7 +158,7 @@ def _fill_obsolete_jobapplication_processed_at(apps, schema_editor):
count = 0
start = time.perf_counter()
print(f"Updating {len(job_apps_ids)} obsolete job applications")
for ids in chunks(job_apps_ids, 10000):
for ids in batched(job_apps_ids, 10000):
job_applications = list(obsolete_qs.filter(pk__in=ids))
for job_application in job_applications:
job_application.processed_at = job_application.obsolete_at or job_application.updated_at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import datetime
import time
from itertools import batched
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vu 👍


from django.db import migrations
from django.utils import timezone


def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i : i + n]


def forward(apps, editor):
JobApplication = apps.get_model("job_applications", "JobApplication")
BATCH_SIZE = 10_000
Expand All @@ -28,7 +24,7 @@ def forward(apps, editor):
).values_list("pk", flat=True)
)
print()
for chunk in chunks(archivable, BATCH_SIZE):
for chunk in batched(archivable, BATCH_SIZE):
matched = JobApplication.objects.filter(pk__in=chunk).update(archived_at=now)
total += matched
print(f"Archived {total} job applications, elapsed {time.perf_counter() - start}s")
Expand Down
8 changes: 4 additions & 4 deletions itou/users/management/commands/new_users_to_brevo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
import logging
from itertools import batched

import httpx
from allauth.account.models import EmailAddress
Expand All @@ -13,7 +14,6 @@
from itou.users.enums import IdentityProvider, UserKind
from itou.users.models import User
from itou.utils.command import BaseCommand
from itou.utils.iterators import chunks


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -74,9 +74,9 @@ def _import_contacts(self, users_data, category):
)

def import_users(self, users, category):
for chunk in chunks(users, self.IMPORT_BATCH_SIZE):
if chunk:
self._import_contacts(chunk, category)
for batch in batched(users, self.IMPORT_BATCH_SIZE):
if batch:
self._import_contacts(batch, category)


class Command(BaseCommand):
Expand Down
5 changes: 2 additions & 3 deletions itou/users/migrations/0011_migrate_birthdate_to_profile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Generated by Django 5.0.8 on 2024-09-02 13:40

import time
from itertools import batched

from django.db import migrations
from django.db.models import F, Q

from itou.utils.iterators import chunks


def _migrate_birthdate(apps, schema_editor):
JobSeekerProfile = apps.get_model("users", "JobSeekerProfile")
Expand All @@ -17,7 +16,7 @@ def _migrate_birthdate(apps, schema_editor):

users_nb = 0
start = time.perf_counter()
for ids in chunks(profile_ids_to_migrate, 1000):
for ids in batched(profile_ids_to_migrate, 1000):
batch_profiles = JobSeekerProfile.objects.filter(pk__in=ids).select_related("user")
profiles = []
for profile in batch_profiles:
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
requires-python = ">=3.11"
requires-python = ">=3.12"

[tool.ruff]
line-length = 119
Expand Down Expand Up @@ -33,7 +33,10 @@ format_js = true
DJANGO_SETTINGS_MODULE = "config.settings.test"
FAIL_INVALID_TEMPLATE_VARS = true
python_files = ["tests*.py", "test_*.py"]
filterwarnings = ["error"]
filterwarnings = [
"error",
"ignore:.*Use timezone-aware objects to represent datetimes in UTC.*:DeprecationWarning:(botocore|django_datadog_logger)",
]
addopts = [
"--reuse-db",
"--strict-markers",
Expand Down
4 changes: 4 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ sentry-sdk==2.17.0 \
--hash=sha256:625955884b862cc58748920f9e21efdfb8e0d4f98cca4ab0d3918576d5b606ad \
--hash=sha256:dd0a05352b78ffeacced73a94e86f38b32e2eae15fff5f30ca5abb568a72eacf
# via -r requirements/base.in
setuptools==75.3.0 \
--hash=sha256:f2504966861356aa38616760c0f66568e535562374995367b4e69c7143cf6bcd \
--hash=sha256:fba5dd4d766e97be1b1681d98712680ae8f2f26d7881245f2ce9e40714f1a686
# via django-easymde
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down
7 changes: 6 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,12 @@ sentry-sdk==2.17.0 \
--hash=sha256:625955884b862cc58748920f9e21efdfb8e0d4f98cca4ab0d3918576d5b606ad \
--hash=sha256:dd0a05352b78ffeacced73a94e86f38b32e2eae15fff5f30ca5abb568a72eacf
# via -r requirements/test.txt
setuptools==75.3.0 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est normal qu'il revienne lui ?
il me semblait qu'il était parti au passage à uv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonne question, et j’avais la réponse : setuptools n’est plus installé par défaut par virtualenv.

gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

https://docs.python.org/3/whatsnew/3.12.html#ensurepip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il vient pour django-easymde.

--hash=sha256:f2504966861356aa38616760c0f66568e535562374995367b4e69c7143cf6bcd \
--hash=sha256:fba5dd4d766e97be1b1681d98712680ae8f2f26d7881245f2ce9e40714f1a686
# via
# -r requirements/test.txt
# django-easymde
shellcheck-py==0.10.0.1 \
--hash=sha256:390826b340b8c19173922b0da5ef7b66ef34d4d087dc48aad3e01f7e77e164d9 \
--hash=sha256:48f08965cafbb3363b265c4ef40628ffced19cb6fc7c4bb5ce72d32cbcfb4bb9 \
Expand Down Expand Up @@ -1702,7 +1708,6 @@ typing-extensions==4.12.2 \
# -r requirements/test.txt
# djlint
# faker
# ipython
# psycopg
tzdata==2024.2 \
--hash=sha256:7d85cc416e9382e69095b7bdf4afd9e3880418a2413feec7069d533d6b4e31cc \
Expand Down
6 changes: 6 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,12 @@ sentry-sdk==2.17.0 \
--hash=sha256:625955884b862cc58748920f9e21efdfb8e0d4f98cca4ab0d3918576d5b606ad \
--hash=sha256:dd0a05352b78ffeacced73a94e86f38b32e2eae15fff5f30ca5abb568a72eacf
# via -r requirements/base.txt
setuptools==75.3.0 \
--hash=sha256:f2504966861356aa38616760c0f66568e535562374995367b4e69c7143cf6bcd \
--hash=sha256:fba5dd4d766e97be1b1681d98712680ae8f2f26d7881245f2ce9e40714f1a686
# via
# -r requirements/base.txt
# django-easymde
shellcheck-py==0.10.0.1 \
--hash=sha256:390826b340b8c19173922b0da5ef7b66ef34d4d087dc48aad3e01f7e77e164d9 \
--hash=sha256:48f08965cafbb3363b265c4ef40628ffced19cb6fc7c4bb5ce72d32cbcfb4bb9 \
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.11
python-3.12
Loading
Loading