Skip to content

Commit

Permalink
chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.9…
Browse files Browse the repository at this point in the history
….0 (WeblateOrg#13465)

* chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.9.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: reorder methods to match Django Style Guide

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Michal Čihař <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 92fd3c9 commit 90fb85f
Show file tree
Hide file tree
Showing 27 changed files with 139 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion scripts/rtd-projects
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ while result["next"]:
print(f"Not a translation {project['name']}: ", project["urls"]["home"])
# Check versions
versions_response = requests.get(
f'{project["_links"]["versions"]}?active=true', headers=AUTH, timeout=1
f"{project['_links']['versions']}?active=true", headers=AUTH, timeout=1
)
versions_response.raise_for_status()
versions = versions_response.json()
Expand Down
3 changes: 1 addition & 2 deletions weblate/accounts/tests/test_avatars.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from weblate.trans.tests.test_views import FixtureTestCase

TEST_URL = (
"https://www.gravatar.com/avatar/"
"55502f40dc8b7c769880b10874abc9d0?d=identicon&s=32"
"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=identicon&s=32"
)


Expand Down
8 changes: 4 additions & 4 deletions weblate/addons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class Meta:
def __str__(self) -> str:
return f"{self.addon.verbose}: {self.project or self.component or 'site-wide'}"

def __init__(self, *args, acting_user: User | None = None, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.acting_user = acting_user

def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
Expand Down Expand Up @@ -134,10 +138,6 @@ def save(
def get_absolute_url(self) -> str:
return reverse("addon-detail", kwargs={"pk": self.pk})

def __init__(self, *args, acting_user: User | None = None, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.acting_user = acting_user

def store_change(self, action) -> None:
Change.objects.create(
action=action,
Expand Down
6 changes: 2 additions & 4 deletions weblate/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ class User(AbstractBaseUser):
verbose_name=gettext_lazy("Teams"),
blank=True,
help_text=gettext_lazy(
"The user is granted all permissions included in "
"membership of these teams."
"The user is granted all permissions included in membership of these teams."
),
)

Expand Down Expand Up @@ -1127,8 +1126,7 @@ class Invitation(models.Model):
Group,
verbose_name=gettext_lazy("Team"),
help_text=gettext_lazy(
"The user is granted all permissions included in "
"membership of these teams."
"The user is granted all permissions included in membership of these teams."
),
on_delete=models.deletion.CASCADE,
)
Expand Down
67 changes: 14 additions & 53 deletions weblate/checks/tests/test_fluent_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __str__(self) -> str:
return f"{fluent_type} ({source!r} -> {target!r})"


class MockCheckModel:
class MockCheckModel: # noqa: B903
# Mock Check object from weblate.checks.models
def __init__(self, unit: MockFluentTransUnit) -> None:
self.unit = unit
Expand Down Expand Up @@ -675,14 +675,8 @@ def test_same_refs(self) -> None:
" [yes] an { -term }\n"
" *[no] a { -term }\n"
"}",
"with { -term.starts-with-vowel ->\n"
" [yes] an\n"
" *[no] a\n"
"} { -term }",
"with { PLATFORM() ->\n"
" [linux] { -term }!\n"
" *[other] { -term }\n"
"}",
"with { -term.starts-with-vowel ->\n [yes] an\n *[no] a\n} { -term }",
"with { PLATFORM() ->\n [linux] { -term }!\n *[other] { -term }\n}",
"with { -term.starts-with-vowel ->\n"
" [yes] an { -term }\n"
" *[no] a { PLATFORM() ->\n"
Expand Down Expand Up @@ -723,10 +717,7 @@ def test_same_refs(self) -> None:
" [one] a variable\n"
" *[other] { $var } variables\n"
"}",
"with { $var }{ $var ->\n"
" [one] variable\n"
" *[other] variables\n"
"}",
"with { $var }{ $var ->\n [one] variable\n *[other] variables\n}",
# $var that is two selection expressions up still gets shared as
# long as each variant below has the same number of refs.
"with { $var ->\n"
Expand All @@ -744,10 +735,7 @@ def test_same_refs(self) -> None:
" [one] { $num } is { message }\n"
" *[other] { $num } are { message }\n"
"}",
"{ $num ->\n"
" [one] { $num } is\n"
" *[other] { $num } are\n"
"} { message }",
"{ $num ->\n [one] { $num } is\n *[other] { $num } are\n} { message }",
"{ $num ->\n"
" [one] a person is { message }\n"
" *[other] { $num } people are { message }\n"
Expand Down Expand Up @@ -854,10 +842,7 @@ def test_same_refs(self) -> None:
(
# Have two variants with different refs, just need at least one
# match for each set of refs.
"value { PLATFORM() ->\n"
" [linux] none\n"
" *[other] with { -term }\n"
"}",
"value { PLATFORM() ->\n [linux] none\n *[other] with { -term }\n}",
"value { PLATFORM() ->\n"
" [linux] none\n"
" [macos] and { -term }\n"
Expand Down Expand Up @@ -1090,10 +1075,7 @@ def test_different_refs(self) -> None:
self.assert_target_check_fails(
self.check,
source,
"{ PLATFORM() ->\n"
" [linux] a { num }\n"
" *[other] b { num }\n"
"}",
"{ PLATFORM() ->\n [linux] a { num }\n *[other] b { num }\n}",
fluent_type,
# Even though we have multiple target variants, they each
# have the same missing and extra refs, so the variants are
Expand Down Expand Up @@ -1210,10 +1192,7 @@ def test_different_refs(self) -> None:
self.assert_target_check_fails(
self.check,
source,
"{ $var ->\n"
" [one] a { $num }\n"
" *[other] { $var } { $num }\n"
"}",
"{ $var ->\n [one] a { $num }\n *[other] { $var } { $num }\n}",
fluent_type,
# Even though the $var ref is shared between the variants,
# since it is an extra ref we do not report it for the
Expand All @@ -1225,10 +1204,7 @@ def test_different_refs(self) -> None:

for source in (
"{ $num } and { $var }",
"{ $var ->\n"
" *[yes] { $num } and { $var }\n"
" [no] { $num }\n"
"}",
"{ $var ->\n *[yes] { $num } and { $var }\n [no] { $num }\n}",
"{ $num ->\n"
" *[other] { $num }\n"
" [0] none\n"
Expand Down Expand Up @@ -1344,10 +1320,7 @@ def test_different_refs(self) -> None:
self.assert_target_check_fails(
self.check,
"{ $n ->\n [a] { $n } and { -term }\n *[b] { message }\n}",
"{ $n ->\n"
" [x] { $n } and { message }\n"
" *[y] { $ns } and { -term }\n"
"}",
"{ $n ->\n [x] { $n } and { message }\n *[y] { $ns } and { -term }\n}",
fluent_type,
"The following variants in the original Fluent value do not "
"have at least one matching variant in the translation with "
Expand Down Expand Up @@ -1473,10 +1446,7 @@ def test_different_refs(self) -> None:
# With source variants having different references.
self.assert_target_check_fails(
self.check,
".title = { PLATFORM() ->\n"
" [linux] with { -term }\n"
" *[other] none\n"
"}",
".title = { PLATFORM() ->\n [linux] with { -term }\n *[other] none\n}",
".title = { -terms }",
"Message",
"The following variants in the original Fluent <code>title</code> "
Expand Down Expand Up @@ -1788,10 +1758,7 @@ def test_html_ok(self) -> None:
'a&{ "{" }b',
'a{ "&{b" }c',
# With variants, each variant is parsed individually.
"<p>add ${ $n ->\n"
" [one] { $n } tab\n"
" *[other] { $n } tabs\n"
"}</p>",
"<p>add ${ $n ->\n [one] { $n } tab\n *[other] { $n } tabs\n}</p>",
# Need not match.
"<p>add ${ $n ->\n"
" [one] { $n } tab <br> more\n"
Expand Down Expand Up @@ -2227,10 +2194,7 @@ def test_html_errors(self) -> None:

# Some errors with variants.
self.assert_html_error(
"{ $var ->\n"
" [one] <span>open\n"
" *[other] none\n"
"} close</span>",
"{ $var ->\n [one] <span>open\n *[other] none\n} close</span>",
fluent_type,
"Unmatched HTML end tag: <code>&lt;/span&gt;</code>.",
)
Expand Down Expand Up @@ -2645,10 +2609,7 @@ def test_different_inner_html(self) -> None:
)
self.assert_target_check_fails(
self.check,
"{ PLATFORM() ->\n"
" [yes] <a data-val='ok'>text</a>\n"
" *[no] none\n"
"}",
"{ PLATFORM() ->\n [yes] <a data-val='ok'>text</a>\n *[no] none\n}",
"<a data-val='not'>text</a>",
fluent_type,
"The following variants in the original Fluent value do not "
Expand Down
2 changes: 1 addition & 1 deletion weblate/checks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_context_data(self, **kwargs):
elif self.check_obj is not None and self.path_object is None:
context["title"] = self.check_obj.name
elif self.check_obj is None and self.path_object is not None:
context["title"] = f'{gettext("Failing checks")} / {self.path_object}'
context["title"] = f"{gettext('Failing checks')} / {self.path_object}"
else:
context["title"] = f"{self.check_obj.name} / {self.path_object}"
if self.check_obj is None:
Expand Down
8 changes: 4 additions & 4 deletions weblate/fonts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Meta:
def __str__(self) -> str:
return f"{self.family} {self.style}"

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.field_errors: dict[str, list[ValidationError]] = {}

def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
) -> None:
Expand All @@ -69,10 +73,6 @@ def save(
def get_absolute_url(self) -> str:
return reverse("font", kwargs={"pk": self.pk, "project": self.project.slug})

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.field_errors: dict[str, list[ValidationError]] = {}

def clean_fields(self, exclude=None) -> None:
self.field_errors = {}
try:
Expand Down
8 changes: 2 additions & 6 deletions weblate/formats/tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,7 @@ def _test_save(self, edit=False) -> None:
# Perform some general assertions about the copyright
self.assertIn('<?xml version="1.1" encoding="UTF-8"?>', newdata)
self.assertIn(
"<!--\n"
" * See the NOTICE file distributed with"
" this work for additional",
"<!--\n * See the NOTICE file distributed with this work for additional",
newdata,
)
self.assertIn(
Expand Down Expand Up @@ -1268,9 +1266,7 @@ def _test_save(self, edit=False) -> None:
# Perform some general assertions about the copyright
self.assertIn('<?xml version="1.1" encoding="UTF-8"?>', newdata)
self.assertIn(
"<!--\n"
" * See the NOTICE file distributed with"
" this work for additional",
"<!--\n * See the NOTICE file distributed with this work for additional",
newdata,
)
self.assertIn(
Expand Down
12 changes: 6 additions & 6 deletions weblate/lang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ def __str__(self) -> str:
return f"{gettext(self.name)} ({self.code})"
return gettext(self.name)

def __init__(self, *args, **kwargs) -> None:
from weblate.utils.stats import LanguageStats

super().__init__(*args, **kwargs)
self.stats = LanguageStats(self)

def save(self, *args, **kwargs):
"""Set default direction for language."""
if not self.direction:
Expand All @@ -666,12 +672,6 @@ def get_absolute_url(self) -> str:
def get_url_path(self):
return ("-", "-", self.code)

def __init__(self, *args, **kwargs) -> None:
from weblate.utils.stats import LanguageStats

super().__init__(*args, **kwargs)
self.stats = LanguageStats(self)

def get_name(self):
"""Not localized version of __str__."""
if self.show_language_code:
Expand Down
6 changes: 2 additions & 4 deletions weblate/machinery/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,7 @@ def mock_response(self) -> None:
)
responses.add(
responses.GET,
"https://api.cognitive.microsofttranslator.com/"
"languages?api-version=3.0",
"https://api.cognitive.microsofttranslator.com/languages?api-version=3.0",
json=MS_SUPPORTED_LANG_RESP,
)
responses.add(
Expand Down Expand Up @@ -736,8 +735,7 @@ def mock_response(self) -> None:
)
responses.add(
responses.GET,
"https://api.cognitive.microsofttranslator.com/"
"languages?api-version=3.0",
"https://api.cognitive.microsofttranslator.com/languages?api-version=3.0",
json=MS_SUPPORTED_LANG_RESP,
)
responses.add(
Expand Down
6 changes: 3 additions & 3 deletions weblate/metrics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ class Meta:
def __str__(self) -> str:
return f"<{self.scope}.{self.relation}>:{self.date}:{self.changes} {self.data}"

def __getitem__(self, item: str):
return self.dict_data[item]

@cached_property
def dict_data(self) -> dict:
return dict(zip_longest(METRIC_ORDER, self.data or [], fillvalue=0))

def __getitem__(self, item: str):
return self.dict_data[item]

def get(self, item: str, default=None):
return self.dict_data.get(item, default)

Expand Down
6 changes: 3 additions & 3 deletions weblate/screenshots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ class Meta:
def __str__(self) -> str:
return self.name

def get_absolute_url(self) -> str:
return reverse("screenshot", kwargs={"pk": self.pk})

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
# Project backup integration
self.import_data: dict[str, Any] = {}
self.import_handle: BinaryIO | None = None

def get_absolute_url(self) -> str:
return reverse("screenshot", kwargs={"pk": self.pk})

@property
def filter_name(self) -> str:
return f"screenshot:{Flags.format_value(self.name)}"
Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def load_components(self, zipfile, callback: Callable | None = None) -> None:
data = json.load(handle)
validate_schema(data, "weblate-component.schema.json")
if data["component"]["vcs"] not in VCS_REGISTRY:
msg = f'Component {data["component"]["name"]} uses unsupported VCS: {data["component"]["vcs"]}'
msg = f"Component {data['component']['name']} uses unsupported VCS: {data['component']['vcs']}"
raise ValueError(msg)
# Validate translations have unique languages
languages = defaultdict(list)
Expand Down
6 changes: 2 additions & 4 deletions weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,7 @@ class CommentForm(forms.Form):
scope = forms.ChoiceField(
label=gettext_lazy("Scope"),
help_text=gettext_lazy(
"Is your comment specific to this "
"translation, or generic for all of them?"
"Is your comment specific to this translation, or generic for all of them?"
),
choices=(
(
Expand Down Expand Up @@ -2442,8 +2441,7 @@ class NewMonolingualUnitForm(NewUnitBaseForm):
source = PluralField(
label=gettext_lazy("Source language text"),
help_text=gettext_lazy(
"You can edit this later, as with any other string in "
"the source language."
"You can edit this later, as with any other string in the source language."
),
required=True,
)
Expand Down
Loading

0 comments on commit 90fb85f

Please sign in to comment.