Skip to content

Commit

Permalink
Update to Python 3.10 (mozilla#3112)
Browse files Browse the repository at this point in the history
In:
* GitHub workflows
* Docker
* Heroku

Also make related flake8, black and pyupgrade fixes (some actually only needed in future versions of python).
  • Loading branch information
flodolo authored Feb 22, 2024
1 parent e4b4946 commit 9cf8902
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 45 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/py-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- name: Install Dependencies
run: |
pip install -U pip
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- name: Install Dependencies
run: |
pip install -U pip
Expand All @@ -52,10 +52,10 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- name: Install Dependencies
run: |
pip install -U pip
pip install -r requirements/lint.txt
- name: pyupgrade
run: pyupgrade --py39-plus *.py `find pontoon -name \*.py`
run: pyupgrade --py310-plus *.py `find pontoon -name \*.py`
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ flake8:
"${DC}" run --rm server flake8 pontoon/

pyupgrade:
"${DC}" run --rm server pyupgrade --exit-zero-even-if-changed --py39-plus *.py `find pontoon -name \*.py`
"${DC}" run --rm server pyupgrade --exit-zero-even-if-changed --py310-plus *.py `find pontoon -name \*.py`

check-pyupgrade:
"${DC}" run --rm server pyupgrade --py39-plus *.py `find pontoon -name \*.py`
"${DC}" run --rm server pyupgrade --py310-plus *.py `find pontoon -name \*.py`

black:
"${DC}" run --rm server black pontoon/
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-bullseye AS server
FROM python:3.10-bullseye AS server

ARG USER_ID=1000
ARG GROUP_ID=1000
Expand Down
4 changes: 2 additions & 2 deletions pontoon/administration/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def test_manage_project_strings_translated_resource(client_superuser):
project = Project.objects.get(id=project.id)
assert project.total_strings == strings_count * locales_count

for l in locales:
locale = Locale.objects.get(id=l.id)
for loc in locales:
locale = Locale.objects.get(id=loc.id)
assert locale.total_strings == strings_count


Expand Down
8 changes: 4 additions & 4 deletions pontoon/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def manage_project(request, slug=None, template="admin_project.html"):

(
ProjectLocale.objects.filter(project=project)
.exclude(locale__pk__in=[l.pk for l in locales])
.exclude(locale__pk__in=[loc.pk for loc in locales])
.delete()
)
for locale in locales:
Expand All @@ -167,7 +167,7 @@ def manage_project(request, slug=None, template="admin_project.html"):
project_locales = ProjectLocale.objects.filter(project=project)

# Update readonly flags
locales_readonly_pks = [l.pk for l in locales_readonly_form]
locales_readonly_pks = [loc.pk for loc in locales_readonly_form]
project_locales.exclude(locale__pk__in=locales_readonly_pks).update(
readonly=False
)
Expand All @@ -179,7 +179,7 @@ def manage_project(request, slug=None, template="admin_project.html"):
locales_pretranslate_form = form.cleaned_data.get(
"locales_pretranslate", []
)
locales_pretranslate_pks = [l.pk for l in locales_pretranslate_form]
locales_pretranslate_pks = [loc.pk for loc in locales_pretranslate_form]
project_locales.exclude(locale__pk__in=locales_pretranslate_pks).update(
pretranslation_enabled=False
)
Expand Down Expand Up @@ -244,7 +244,7 @@ def manage_project(request, slug=None, template="admin_project.html"):
{
"name": p.name,
# Cannot use values_list() here, because it hits the DB again
"locales": [l.pk for l in p.locales.all()],
"locales": [loc.pk for loc in p.locales.all()],
}
)

Expand Down
2 changes: 1 addition & 1 deletion pontoon/checks/libraries/compare_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, key, raw_val, pre_comment):

@property
def all(self):
return f"%s = %s"
return "%s = %s"

def __repr__(self):
return 'ComparePropertiesEntity<key="{}",raw_val="{}",pre_comment="{}">'.format(
Expand Down
10 changes: 5 additions & 5 deletions pontoon/contributors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def users_with_translations_counts(
Prefetch("translators_group__user_set", to_attr="fetched_translators"),
)

for l in locales:
for user in l.managers_group.fetched_managers:
managers[user].add(l.code)
for user in l.translators_group.fetched_translators:
translators[user].add(l.code)
for loc in locales:
for user in loc.managers_group.fetched_managers:
managers[user].add(loc.code)
for user in loc.translators_group.fetched_translators:
translators[user].add(loc.code)

# Assign properties to user objects.
contributors = User.objects.filter(pk__in=user_stats.keys())
Expand Down
4 changes: 3 additions & 1 deletion pontoon/contributors/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ def settings(request):
user_profile_form = forms.UserProfileForm(instance=profile)

selected_locales = list(profile.sorted_locales)
available_locales = Locale.objects.exclude(pk__in=[l.pk for l in selected_locales])
available_locales = Locale.objects.exclude(
pk__in=[loc.pk for loc in selected_locales]
)

default_homepage_locale = Locale(name="Default homepage", code="")
all_locales = list(Locale.objects.all())
Expand Down
4 changes: 2 additions & 2 deletions pontoon/pretranslation/transformer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from copy import deepcopy
from typing import Callable, Optional, cast
from typing import Callable, cast

from fluent.syntax import ast as FTL
from fluent.syntax.serializer import serialize_expression
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(
self,
locale: Locale,
entry: FTL.EntryType,
callback: Callable[[str, str], tuple[Optional[str], str]],
callback: Callable[[str, str], tuple[str | None, str]],
preserve_placeables: bool = None,
):
prep = PreparePretranslation(locale)
Expand Down
2 changes: 1 addition & 1 deletion pontoon/sync/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, db_project, vcs_project, now, locale=None):
self.locale = locale

# Store locales and resources for FK relationships.
self.locales = {l.code: l for l in Locale.objects.all()}
self.locales = {loc.code: loc for loc in Locale.objects.all()}
self.resources = {r.path: r for r in self.db_project.resources.all()}

self.executed = False
Expand Down
12 changes: 4 additions & 8 deletions pontoon/sync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ def update_translated_resources_no_files(db_project, locale, changed_resources):
# only create TranslatedResources if the file is present in the repository for the locale,
# which we cannot check without files.
if not resource.is_asymmetric:
log.error(
"Unable to calculate stats for asymmetric resource: {resource}.".format(
resource
)
)
log.error(f"Unable to calculate stats for asymmetric resource: {resource}")
continue

translatedresource, _ = TranslatedResource.objects.get_or_create(
Expand Down Expand Up @@ -434,11 +430,11 @@ def get_changed_locales(db_project, locales, now):

# Check if any locale for which the exception was raised hasn't been processed yet.
# For those locales we can't be sure if a change happened, so we assume it did.
for l in error_locale_pks:
if l not in changed_locale_pks + unchanged_locale_pks:
for loc in error_locale_pks:
if loc not in changed_locale_pks + unchanged_locale_pks:
log.error(
"Unable to fetch latest commit hash for locale {locale} in project {project}".format(
locale=Locale.objects.get(pk=l), project=db_project.slug
locale=Locale.objects.get(pk=loc), project=db_project.slug
)
)
changed_locale_pks.append(locale.pk)
Expand Down
4 changes: 2 additions & 2 deletions pontoon/sync/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def sync_translations(
# We should also sync files for which source file change - but only for read-only locales.
# See https://github.com/mozilla/pontoon/issues/2068 for more details.
if added_and_changed_resources:
changed_locales_pks = [l.pk for l in locales]
readonly_locales_pks = [l.pk for l in readonly_locales]
changed_locales_pks = [loc.pk for loc in locales]
readonly_locales_pks = [loc.pk for loc in readonly_locales]
locales = db_project.locales.filter(
pk__in=changed_locales_pks + readonly_locales_pks
)
Expand Down
4 changes: 2 additions & 2 deletions pontoon/sync/vcs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ def resources(self):
continue
locales = []

locales = {l for l in locales if l in self.locales}
locales = {loc for loc in locales if loc in self.locales}
self.synced_locales.update(locales)

log.debug(
"Detected resource file {} for {}".format(
path, ",".join([l.code for l in locales]) or "source"
path, ",".join([loc.code for loc in locales]) or "source"
)
)

Expand Down
2 changes: 1 addition & 1 deletion pontoon/tags/tests/fixtures/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _tag_iterator(things, **kwargs):
# `things` can be either translations or translated_resources, but
# they must have their `locale`, `project`, `resource` and
# `resource.path` denormalized where required.
locales = list(l.id for l in kwargs.get("locales", []))
locales = list(loc.id for loc in kwargs.get("locales", []))
projects = list(p.id for p in kwargs.get("projects", []))
slug = kwargs.get("slug", None)
path = kwargs.get("path", None)
Expand Down
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# ./docker/compile_requirements.sh
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# ./docker/compile_requirements.sh
Expand Down
6 changes: 1 addition & 5 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# ./docker/compile_requirements.sh
Expand Down Expand Up @@ -66,7 +66,3 @@ tomli==1.2.2 \
--hash=sha256:c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee \
--hash=sha256:f04066f68f5554911363063a30b108d2b5a5b1a010aa8b6132af78489fe3aade
# via black
typing-extensions==4.5.0 \
--hash=sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb \
--hash=sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4
# via black
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# ./docker/compile_requirements.sh
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.9.18
python-3.10.13

0 comments on commit 9cf8902

Please sign in to comment.