diff --git a/.github/workflows/py-lint.yml b/.github/workflows/py-lint.yml index a7654269bc..8d5f10ba50 100644 --- a/.github/workflows/py-lint.yml +++ b/.github/workflows/py-lint.yml @@ -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 @@ -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 @@ -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` diff --git a/Makefile b/Makefile index ff5620f94a..e9a3b4d9c3 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/docker/Dockerfile b/docker/Dockerfile index 44b4ed2942..32c9ad4a3a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/pontoon/administration/tests/test_views.py b/pontoon/administration/tests/test_views.py index 7c69d8248b..f05604b411 100644 --- a/pontoon/administration/tests/test_views.py +++ b/pontoon/administration/tests/test_views.py @@ -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 diff --git a/pontoon/administration/views.py b/pontoon/administration/views.py index e9488edb67..1aa7c38424 100644 --- a/pontoon/administration/views.py +++ b/pontoon/administration/views.py @@ -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: @@ -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 ) @@ -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 ) @@ -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()], } ) diff --git a/pontoon/checks/libraries/compare_locales.py b/pontoon/checks/libraries/compare_locales.py index a05b9ec1c9..999fe35fae 100644 --- a/pontoon/checks/libraries/compare_locales.py +++ b/pontoon/checks/libraries/compare_locales.py @@ -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'.format( diff --git a/pontoon/contributors/utils.py b/pontoon/contributors/utils.py index 97c985a2c7..ab679811e9 100644 --- a/pontoon/contributors/utils.py +++ b/pontoon/contributors/utils.py @@ -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()) diff --git a/pontoon/contributors/views.py b/pontoon/contributors/views.py index 34c07d9df6..6a64e2ce90 100644 --- a/pontoon/contributors/views.py +++ b/pontoon/contributors/views.py @@ -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()) diff --git a/pontoon/pretranslation/transformer.py b/pontoon/pretranslation/transformer.py index af5338efbd..a4f00d4548 100644 --- a/pontoon/pretranslation/transformer.py +++ b/pontoon/pretranslation/transformer.py @@ -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 @@ -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) diff --git a/pontoon/sync/changeset.py b/pontoon/sync/changeset.py index f4e9d0122f..b607160273 100644 --- a/pontoon/sync/changeset.py +++ b/pontoon/sync/changeset.py @@ -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 diff --git a/pontoon/sync/core.py b/pontoon/sync/core.py index b6ff82f227..4954ffc41d 100644 --- a/pontoon/sync/core.py +++ b/pontoon/sync/core.py @@ -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( @@ -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) diff --git a/pontoon/sync/tasks.py b/pontoon/sync/tasks.py index 410918f5ed..e1c0bf63a2 100644 --- a/pontoon/sync/tasks.py +++ b/pontoon/sync/tasks.py @@ -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 ) diff --git a/pontoon/sync/vcs/models.py b/pontoon/sync/vcs/models.py index f2cf8c292a..7bfac01ade 100644 --- a/pontoon/sync/vcs/models.py +++ b/pontoon/sync/vcs/models.py @@ -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" ) ) diff --git a/pontoon/tags/tests/fixtures/tags.py b/pontoon/tags/tests/fixtures/tags.py index fab593bc9a..63c2787820 100644 --- a/pontoon/tags/tests/fixtures/tags.py +++ b/pontoon/tags/tests/fixtures/tags.py @@ -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) diff --git a/requirements/default.txt b/requirements/default.txt index ff12c6a80d..9034ef611c 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -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 diff --git a/requirements/dev.txt b/requirements/dev.txt index 83170673bd..abea031b2e 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -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 diff --git a/requirements/lint.txt b/requirements/lint.txt index 8ff427010e..1992d18738 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -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 @@ -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 diff --git a/requirements/test.txt b/requirements/test.txt index 947cf3739b..268fc70e3c 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -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 diff --git a/runtime.txt b/runtime.txt index 815b82f771..5fa6f4127a 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.9.18 +python-3.10.13