Skip to content

Commit 4ae0542

Browse files
renovate[bot]asadali145pre-commit-ci[bot]
authored
fix(deps): update python to v3.12.5 (#3003)
* fix(deps): update python to v3.12.5 * disable cache for a moment and update python version for ruff * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comment env create in ci * reorder action steps * update cache process ci * update python version * fix ruff lint * rename step[ --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Asad Ali <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7181c58 commit 4ae0542

38 files changed

+106
-91
lines changed

.github/workflows/ci.yml

+17-4
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,32 @@ jobs:
4545
- name: Apt install
4646
run: cat Aptfile | sudo xargs apt-get install
4747

48+
- name: Set up Python
49+
id: setup-python
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: "3.12.5"
53+
4854
- name: Install poetry
4955
uses: snok/install-poetry@v1
5056
with:
5157
version: 1.8.2
5258
virtualenvs-create: true
5359
virtualenvs-in-project: true
60+
virtualenvs-path: .venv
5461

55-
- name: Set up Python
56-
uses: actions/setup-python@v4
62+
- name: Load cached venv
63+
id: cached-poetry-dependencies
64+
uses: actions/cache@v4
5765
with:
58-
python-version: "3.12.4"
59-
cache: "poetry"
66+
path: .venv
67+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
6068

6169
- name: Install dependencies
70+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
71+
run: poetry install --no-interaction --no-root
72+
73+
- name: Install project
6274
run: poetry install --no-interaction
6375

6476
# Configurations required for elasticsearch.
@@ -93,6 +105,7 @@ jobs:
93105

94106
- name: Tests
95107
run: |
108+
source .venv/bin/activate
96109
export MEDIA_ROOT="$(mktemp -d)"
97110
poetry run ./scripts/test/python_tests.sh
98111
env:

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12.4
1+
FROM python:3.12.5
22
LABEL maintainer "ODL DevOps <[email protected]>"
33

44
# Add package files, install updated node and pip

authentication/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create_user_with_generated_username(serializer, initial_username):
5757
while created_user is None and attempts < USERNAME_COLLISION_ATTEMPTS:
5858
try:
5959
created_user = serializer.save(username=username)
60-
except IntegrityError as exc: # noqa: PERF203
60+
except IntegrityError as exc:
6161
if not is_duplicate_username_error(exc):
6262
raise
6363
username = find_available_username(initial_username)

b2b_ecommerce/factories.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Factories for b2b_ecommerce"""
22

3-
from datetime import timezone
3+
from datetime import UTC
44

55
import factory
66
from factory import fuzzy
@@ -46,10 +46,10 @@ class B2BCouponFactory(DjangoModelFactory):
4646
name = fuzzy.FuzzyText()
4747
coupon_code = fuzzy.FuzzyText()
4848
activation_date = factory.Faker(
49-
"date_time_this_year", before_now=True, after_now=False, tzinfo=timezone.utc
49+
"date_time_this_year", before_now=True, after_now=False, tzinfo=UTC
5050
)
5151
expiration_date = factory.Faker(
52-
"date_time_this_year", before_now=False, after_now=True, tzinfo=timezone.utc
52+
"date_time_this_year", before_now=False, after_now=True, tzinfo=UTC
5353
)
5454
enabled = True
5555
reusable = False

cms/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import itertools
44
import logging
5-
from datetime import MAXYEAR, datetime, timezone
5+
from datetime import MAXYEAR, UTC, datetime
66

77
from django.contrib.contenttypes.models import ContentType
88
from wagtail.models import Page, Site
@@ -44,7 +44,7 @@ def filter_and_sort_catalog_pages(
4444

4545
page_run_dates = {
4646
page: page.product.next_run_date
47-
or datetime(year=MAXYEAR, month=1, day=1, tzinfo=timezone.utc)
47+
or datetime(year=MAXYEAR, month=1, day=1, tzinfo=UTC)
4848
for page in itertools.chain(
4949
valid_program_pages,
5050
valid_course_pages,

cms/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def clean(self):
2626

2727
cleaned_data = super().clean()
2828
parent_page = self.parent_page.specific
29-
if (isinstance(parent_page, (CoursePage, ProgramPage))) and not cleaned_data[
29+
if (isinstance(parent_page, (CoursePage, ProgramPage))) and not cleaned_data[ # noqa: UP038
3030
"signatories"
3131
]:
3232
self.add_error("signatories", "Signatories is a required field.")

cms/migrations/0054_create_external_courseware_asociations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by Django 3.2.18 on 2023-03-16 12:26
22

33

4-
from datetime import datetime, timezone
4+
from datetime import UTC, datetime
55

66
import django.db.models.deletion
77
from django.db import migrations, models
@@ -13,7 +13,7 @@
1313

1414
def get_zone_aware_datetime(date):
1515
"""Takes a date object and returns a zone aware datetime"""
16-
return datetime.combine(date, datetime.max.time(), timezone.utc) if date else None
16+
return datetime.combine(date, datetime.max.time(), UTC) if date else None
1717

1818

1919
def check_and_generate_associated_product(

cms/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ def is_course_page(self):
11231123
@property
11241124
def is_internal_or_external_course_page(self):
11251125
"""Gets the product page type, this is used for sorting product pages."""
1126-
return isinstance(self, (CoursePage, ExternalCoursePage))
1126+
return isinstance(self, (CoursePage, ExternalCoursePage)) # noqa: UP038
11271127

11281128
@property
11291129
def external_courseware_url(self):
@@ -1148,7 +1148,7 @@ def is_program_page(self):
11481148
@property
11491149
def is_internal_or_external_program_page(self):
11501150
"""Check whether the page is an internal or external program page."""
1151-
return isinstance(self, (ProgramPage, ExternalProgramPage))
1151+
return isinstance(self, (ProgramPage, ExternalProgramPage)) # noqa: UP038
11521152

11531153
@property
11541154
def is_external_page(self):

courses/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def create_run_enrollments(
143143
if not created and not enrollment.active:
144144
enrollment.edx_enrolled = edx_request_success
145145
enrollment.reactivate_and_save()
146-
except: # noqa: E722, PERF203
146+
except: # noqa: E722
147147
mail_api.send_enrollment_failure_message(order, run, details=format_exc())
148148
log.exception(
149149
"Failed to create/update enrollment record (user: %s, run: %s, order: %s)",
@@ -184,7 +184,7 @@ def create_program_enrollments(user, programs, order=None, company=None):
184184
)
185185
if not created and not enrollment.active:
186186
enrollment.reactivate_and_save()
187-
except: # noqa: E722, PERF203
187+
except: # noqa: E722
188188
mail_api.send_enrollment_failure_message(
189189
order, program, details=format_exc()
190190
)

courses/credentials.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def build_course_run_credential(certificate: CourseRunCertificate) -> dict:
8080

8181

8282
def build_digital_credential(
83-
certificate: ProgramCertificate | CourseRunCertificate, # noqa: FA102
83+
certificate: ProgramCertificate | CourseRunCertificate,
8484
learner_did: LearnerDID,
8585
) -> dict:
8686
"""Function for building certificate digital credentials"""

courses/factories.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Factories for creating course data in tests"""
22

3-
from datetime import timezone
3+
from datetime import UTC
44

55
import factory
66
import faker
@@ -99,19 +99,19 @@ class CourseRunFactory(DjangoModelFactory):
9999
run_tag = factory.Sequence("R{}".format)
100100
courseware_url_path = factory.Faker("uri")
101101
start_date = factory.Faker(
102-
"date_time_this_month", before_now=True, after_now=False, tzinfo=timezone.utc
102+
"date_time_this_month", before_now=True, after_now=False, tzinfo=UTC
103103
)
104104
end_date = factory.Faker(
105-
"date_time_this_year", before_now=False, after_now=True, tzinfo=timezone.utc
105+
"date_time_this_year", before_now=False, after_now=True, tzinfo=UTC
106106
)
107107
enrollment_start = factory.Faker(
108-
"date_time_this_month", before_now=True, after_now=False, tzinfo=timezone.utc
108+
"date_time_this_month", before_now=True, after_now=False, tzinfo=UTC
109109
)
110110
enrollment_end = factory.Faker(
111-
"date_time_this_month", before_now=False, after_now=True, tzinfo=timezone.utc
111+
"date_time_this_month", before_now=False, after_now=True, tzinfo=UTC
112112
)
113113
expiration_date = factory.Faker(
114-
"date_time_between", start_date="+1y", end_date="+2y", tzinfo=timezone.utc
114+
"date_time_between", start_date="+1y", end_date="+2y", tzinfo=UTC
115115
)
116116
live = True
117117

@@ -120,10 +120,10 @@ class Meta:
120120

121121
class Params:
122122
past_start = factory.Trait(
123-
start_date=factory.Faker("past_datetime", tzinfo=timezone.utc)
123+
start_date=factory.Faker("past_datetime", tzinfo=UTC)
124124
)
125125
past_enrollment_end = factory.Trait(
126-
enrollment_end=factory.Faker("past_datetime", tzinfo=timezone.utc)
126+
enrollment_end=factory.Faker("past_datetime", tzinfo=UTC)
127127
)
128128

129129

courses/migrations/0029_revert_certificates_prior_aug_8.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Generated by Django 3.2.15 on 2022-10-26 15:40
22

3-
from datetime import datetime, timezone
3+
from datetime import UTC, datetime
44

55
from django.db import migrations
66

77
from cms.models import CertificatePage
88
from courses.models import CourseRunCertificate, ProgramCertificate
99

10-
AUGUST_8_2022 = datetime(2022, 8, 8, tzinfo=timezone.utc)
11-
SEPTEMBER_20_2022 = datetime(2022, 9, 20, tzinfo=timezone.utc)
10+
AUGUST_8_2022 = datetime(2022, 8, 8, tzinfo=UTC)
11+
SEPTEMBER_20_2022 = datetime(2022, 9, 20, tzinfo=UTC)
1212

1313

1414
def get_course_certificate_cms_page(course_run_cert):

courses/serializers_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Tests for course serializers
33
"""
44

5-
from datetime import datetime, timedelta, timezone
5+
from datetime import UTC, datetime, timedelta
66

77
import factory
88
import pytest
@@ -106,7 +106,7 @@ def test_serialize_program( # noqa: PLR0913
106106

107107
non_live_run = CourseRunFactory.create(
108108
course=course1,
109-
end_date=datetime.max.replace(tzinfo=timezone.utc),
109+
end_date=datetime.max.replace(tzinfo=UTC),
110110
expiration_date=None,
111111
live=False,
112112
)
@@ -221,7 +221,7 @@ def test_serialize_course( # noqa: PLR0913
221221
marketing_hubspot_form_id,
222222
):
223223
"""Test Course serialization"""
224-
now = datetime.now(tz=timezone.utc)
224+
now = datetime.now(tz=UTC)
225225
if is_anonymous:
226226
mock_context["request"].user = AnonymousUser()
227227
if all_runs:

courses/sync_external_courses/emeritus_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""API for Emeritus course sync"""
2+
13
import json
24
import logging
35
import re

courses/tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def exception_logging_generator(generator):
8888
while True:
8989
try:
9090
yield next(generator)
91-
except StopIteration: # noqa: PERF203
91+
except StopIteration:
9292
return
9393
except HTTPError as exc:
9494
log.exception("EdX API error for fetching user grades %s:", exc) # noqa: TRY401

courses/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def sync_course_runs(runs):
271271
course_id=run.courseware_id,
272272
username=settings.OPENEDX_SERVICE_WORKER_USERNAME,
273273
)
274-
except HTTPError as e: # noqa: PERF203
274+
except HTTPError as e:
275275
failure_count += 1
276276
if e.response.status_code == HTTP_404_NOT_FOUND:
277277
log.error( # noqa: TRY400

courseware/api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def repair_faulty_courseware_users():
413413
# edX is our only courseware for the time being. If a different courseware is added, this
414414
# function will need to be updated.
415415
created_user, created_auth_token = repair_faulty_edx_user(user)
416-
except HTTPError as exc: # noqa: PERF203
416+
except HTTPError as exc:
417417
log.exception(
418418
"Failed to repair faulty user %s (%s). %s",
419419
user.username,
@@ -597,7 +597,7 @@ def get_edx_grades_with_users(course_run, user=None):
597597
for edx_grade in all_grades:
598598
try:
599599
user = User.objects.get(username=edx_grade.username)
600-
except User.DoesNotExist: # noqa: PERF203
600+
except User.DoesNotExist:
601601
log.warning("User with username %s not found", edx_grade.username)
602602
else:
603603
yield edx_grade, user
@@ -651,7 +651,7 @@ def enroll_in_edx_course_runs(user, course_runs, force_enrollment=True): # noqa
651651
force_enrollment=force_enrollment,
652652
)
653653
results.append(result)
654-
except HTTPError as exc: # noqa: PERF203
654+
except HTTPError as exc:
655655
# If there is an error message and it indicates that the preferred enrollment mode was the cause of the
656656
# error, log an error and try to enroll the user in 'audit' mode as a failover.
657657
if not is_json_response(exc.response):

courseware/factories.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Courseware factories"""
22

3-
from datetime import timedelta, timezone
3+
from datetime import UTC, timedelta
44

55
from factory import Faker, LazyAttribute, SubFactory, Trait
66
from factory.django import DjangoModelFactory
@@ -28,7 +28,7 @@ class OpenEdxApiAuthFactory(DjangoModelFactory):
2828
refresh_token = Faker("pystr", max_chars=30)
2929
access_token = Faker("pystr", max_chars=30)
3030
access_token_expires_on = Faker(
31-
"date_time_between", start_date="+1d", end_date="+2d", tzinfo=timezone.utc
31+
"date_time_between", start_date="+1d", end_date="+2d", tzinfo=UTC
3232
)
3333

3434
class Meta:

ecommerce/api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,9 @@ class ValidatedBasket(NamedTuple):
10151015
basket: Basket
10161016
basket_item: BasketItem
10171017
product_version: ProductVersion
1018-
coupon_version: CouponVersion | None # noqa: FA102
1019-
run_selection_ids: Iterable[int] | None # noqa: FA102
1020-
data_consent_users: Iterable[DataConsentUser] | None # noqa: FA102
1018+
coupon_version: CouponVersion | None
1019+
run_selection_ids: Iterable[int] | None
1020+
data_consent_users: Iterable[DataConsentUser] | None
10211021

10221022

10231023
def _validate_basket_contents(basket):

ecommerce/api_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,11 @@ def test_delete_expired_basket(patch_now):
11121112
Test to verify that the expired baskets are deleted on calling clear_and_delete_baskets fn without user argument
11131113
"""
11141114
patch_now.return_value = datetime.datetime.now(
1115-
tz=datetime.timezone.utc
1115+
tz=datetime.UTC
11161116
) - datetime.timedelta(days=settings.BASKET_EXPIRY_DAYS)
11171117
BasketFactory.create_batch(3)
11181118
patch_now.return_value = datetime.datetime.now(
1119-
tz=datetime.timezone.utc
1119+
tz=datetime.UTC
11201120
) + datetime.timedelta(days=settings.BASKET_EXPIRY_DAYS + 1)
11211121
unexpired_baskets = BasketFactory.create_batch(3)
11221122
patch_now.stop()

ecommerce/factories.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Factories for ecommerce models
33
"""
44

5-
from datetime import timezone
5+
from datetime import UTC
66

77
import faker
88
from factory import Faker, LazyAttribute, SubFactory, Trait, fuzzy, post_generation
@@ -128,10 +128,10 @@ class CouponPaymentVersionFactory(DjangoModelFactory):
128128
amount = fuzzy.FuzzyDecimal(0, 1, precision=5)
129129
company = SubFactory(CompanyFactory)
130130
activation_date = Faker(
131-
"date_time_this_year", before_now=True, after_now=False, tzinfo=timezone.utc
131+
"date_time_this_year", before_now=True, after_now=False, tzinfo=UTC
132132
)
133133
expiration_date = Faker(
134-
"date_time_this_year", before_now=False, after_now=True, tzinfo=timezone.utc
134+
"date_time_this_year", before_now=False, after_now=True, tzinfo=UTC
135135
)
136136

137137
class Meta:

ecommerce/views_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""ecommerce tests for views"""
22

33
import json
4-
from datetime import datetime, timedelta, timezone
4+
from datetime import UTC, datetime, timedelta
55
from urllib.parse import quote_plus, urljoin
66

77
import factory
@@ -975,7 +975,7 @@ def test_patch_basket_data_consents(basket_and_agreement, as_owner):
975975
)
976976
if as_owner:
977977
assert resp.json()["data_consents"][0]["consent_date"] >= datetime.now(
978-
tz=timezone.utc
978+
tz=UTC
979979
).strftime("%Y-%m-%dT00:00:00Z")
980980
else:
981981
assert resp.json()["data_consents"] == []

0 commit comments

Comments
 (0)