Skip to content

Commit b6e2167

Browse files
ci(ruff)!: update ruff linter config, refactor to comply (#499)
* ci: update ruff linter config - Set line length to 100 - Enforce Google-style docstrings - Lint docstrings and imports * ci(ruff): exclude missing docstring warnings * ci(ruff): exclude docstring checks from tests dir * fix(ruff): change top level linter setting Fix Ruff warning: `warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`: - 'per-file-ignores' -> 'lint.per-file-ignores'`. * chore: format with ruff * add `.git-blame-ignore-revs` * ci(ruff): add E402 and F541 checks * ci(ruff): add FBT003 check (#500) * ci(ruff): add T20 check * ci(ruff)!: add N check, refactor method names * ci(ruff): add E501 check, refactor strings Much commented-out code is removed in this commit. * update `.git-blame-ignore.revs` --------- Co-authored-by: yed <yedpodtrzitko@users.noreply.github.com>
1 parent c159638 commit b6e2167

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+710
-1388
lines changed

.git-blame-ignore-revs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Date: Thu, 12 Sep 2024 19:38:58 -0700
2+
# chore: format with ruff
3+
308be42bd21c3483098088ceb2ebc89208f5f26c
4+
5+
# Date: Thu, 12 Sep 2024 21:43:01 -0700
6+
# ci(ruff): add E402 and F541 checks
7+
f52c1fc541fef0044edf5463a0818e17601e5fab
8+
9+
# Date: Fri, 13 Sep 2024 11:43:08 +0700
10+
# ci(ruff): add FBT003 check
11+
16dd6346e4d7e86212d4df1ac91c19d9cb11c572
12+
13+
# Date: Fri, 13 Sep 2024 11:43:08 +0700
14+
# Merge #500 into #499
15+
3baa07bd33decad5f048ff9ad7a36188bb2956b7
16+
17+
# Date: Thu, 12 Sep 2024 21:50:00 -0700
18+
# ci(ruff): add T20 check
19+
162bcf5a6c7b2e4a39ec7e571375998c9859a42a
20+
21+
# Date: Thu, 12 Sep 2024 22:28:24 -0700
22+
# ci(ruff)!: add N check, refactor method names
23+
5bc815cfba5b92bca8fc646b92cb4a12222f3a0e
24+
25+
# Date: Thu, 12 Sep 2024 23:40:24 -0700
26+
# ci(ruff): add E501 check, refactor strings
27+
836bb0155d0eae3448a752e3f2690061803707b4

pyproject.toml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
11
[tool.ruff]
22
exclude = ["main_window.py", "home_ui.py", "resources.py", "resources_rc.py"]
3+
line-length = 100
4+
5+
[tool.ruff.lint.per-file-ignores]
6+
"tagstudio/tests/**" = ["D", "E402"]
7+
8+
[tool.ruff.lint.pydocstyle]
9+
convention = "google"
310

411
[tool.ruff.lint]
5-
select = ["E", "F", "UP", "B", 'SIM']
6-
ignore = ["E402", "E501", "F541"]
12+
select = [
13+
"B",
14+
"D",
15+
"E",
16+
"F",
17+
"FBT003",
18+
"I",
19+
"N",
20+
"SIM",
21+
"T20",
22+
"UP",
23+
]
24+
ignore = [
25+
"D100",
26+
"D101",
27+
"D102",
28+
"D103",
29+
"D104",
30+
"D105",
31+
"D106",
32+
"D107",
33+
]
734

835
[tool.mypy]
936
strict_optional = false
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from .models import Entry
2-
from .library import Library
3-
from .models import Tag
41
from .enums import ItemType
2+
from .library import Library
3+
from .models import Entry, Tag
54

65
__all__ = ["Entry", "Library", "Tag", "ItemType"]

tagstudio/src/core/library/alchemy/enums.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def __post_init__(self):
104104

105105
else:
106106
self.tag = self.tag and self.tag.strip()
107-
self.tag_id = (
108-
int(self.tag_id) if str(self.tag_id).isnumeric() else self.tag_id
109-
)
107+
self.tag_id = int(self.tag_id) if str(self.tag_id).isnumeric() else self.tag_id
110108
self.path = self.path and str(self.path).strip()
111109
self.name = self.name and self.name.strip()
112110
self.id = int(self.id) if str(self.id).isnumeric() else self.id
@@ -118,10 +116,8 @@ def __post_init__(self):
118116

119117
@property
120118
def summary(self):
121-
"""Show query summary"""
122-
return (
123-
self.query or self.tag or self.name or self.tag_id or self.path or self.id
124-
)
119+
"""Show query summary."""
120+
return self.query or self.tag or self.name or self.tag_id or self.path or self.id
125121

126122
@property
127123
def limit(self):

tagstudio/src/core/library/alchemy/fields.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from dataclasses import dataclass, field
44
from enum import Enum
5-
from typing import Any, TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Any
66

77
from sqlalchemy import ForeignKey
8-
from sqlalchemy.orm import Mapped, mapped_column, relationship, declared_attr
8+
from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship
99

1010
from .db import Base
1111
from .enums import FieldTypeEnum
@@ -18,27 +18,27 @@ class BaseField(Base):
1818
__abstract__ = True
1919

2020
@declared_attr
21-
def id(cls) -> Mapped[int]:
21+
def id(cls) -> Mapped[int]: # noqa: N805
2222
return mapped_column(primary_key=True, autoincrement=True)
2323

2424
@declared_attr
25-
def type_key(cls) -> Mapped[str]:
25+
def type_key(cls) -> Mapped[str]: # noqa: N805
2626
return mapped_column(ForeignKey("value_type.key"))
2727

2828
@declared_attr
29-
def type(cls) -> Mapped[ValueType]:
29+
def type(cls) -> Mapped[ValueType]: # noqa: N805
3030
return relationship(foreign_keys=[cls.type_key], lazy=False) # type: ignore
3131

3232
@declared_attr
33-
def entry_id(cls) -> Mapped[int]:
33+
def entry_id(cls) -> Mapped[int]: # noqa: N805
3434
return mapped_column(ForeignKey("entries.id"))
3535

3636
@declared_attr
37-
def entry(cls) -> Mapped[Entry]:
37+
def entry(cls) -> Mapped[Entry]: # noqa: N805
3838
return relationship(foreign_keys=[cls.entry_id]) # type: ignore
3939

4040
@declared_attr
41-
def position(cls) -> Mapped[int]:
41+
def position(cls) -> Mapped[int]: # noqa: N805
4242
return mapped_column(default=0)
4343

4444
def __hash__(self):
@@ -125,52 +125,36 @@ class DefaultField:
125125

126126

127127
class _FieldID(Enum):
128-
"""Only for bootstrapping content of DB table"""
128+
"""Only for bootstrapping content of DB table."""
129129

130-
TITLE = DefaultField(
131-
id=0, name="Title", type=FieldTypeEnum.TEXT_LINE, is_default=True
132-
)
130+
TITLE = DefaultField(id=0, name="Title", type=FieldTypeEnum.TEXT_LINE, is_default=True)
133131
AUTHOR = DefaultField(id=1, name="Author", type=FieldTypeEnum.TEXT_LINE)
134132
ARTIST = DefaultField(id=2, name="Artist", type=FieldTypeEnum.TEXT_LINE)
135133
URL = DefaultField(id=3, name="URL", type=FieldTypeEnum.TEXT_LINE)
136134
DESCRIPTION = DefaultField(id=4, name="Description", type=FieldTypeEnum.TEXT_LINE)
137135
NOTES = DefaultField(id=5, name="Notes", type=FieldTypeEnum.TEXT_BOX)
138136
TAGS = DefaultField(id=6, name="Tags", type=FieldTypeEnum.TAGS)
139-
TAGS_CONTENT = DefaultField(
140-
id=7, name="Content Tags", type=FieldTypeEnum.TAGS, is_default=True
141-
)
142-
TAGS_META = DefaultField(
143-
id=8, name="Meta Tags", type=FieldTypeEnum.TAGS, is_default=True
144-
)
137+
TAGS_CONTENT = DefaultField(id=7, name="Content Tags", type=FieldTypeEnum.TAGS, is_default=True)
138+
TAGS_META = DefaultField(id=8, name="Meta Tags", type=FieldTypeEnum.TAGS, is_default=True)
145139
COLLATION = DefaultField(id=9, name="Collation", type=FieldTypeEnum.TEXT_LINE)
146140
DATE = DefaultField(id=10, name="Date", type=FieldTypeEnum.DATETIME)
147141
DATE_CREATED = DefaultField(id=11, name="Date Created", type=FieldTypeEnum.DATETIME)
148-
DATE_MODIFIED = DefaultField(
149-
id=12, name="Date Modified", type=FieldTypeEnum.DATETIME
150-
)
142+
DATE_MODIFIED = DefaultField(id=12, name="Date Modified", type=FieldTypeEnum.DATETIME)
151143
DATE_TAKEN = DefaultField(id=13, name="Date Taken", type=FieldTypeEnum.DATETIME)
152-
DATE_PUBLISHED = DefaultField(
153-
id=14, name="Date Published", type=FieldTypeEnum.DATETIME
154-
)
144+
DATE_PUBLISHED = DefaultField(id=14, name="Date Published", type=FieldTypeEnum.DATETIME)
155145
# ARCHIVED = DefaultField(id=15, name="Archived", type=CheckboxField.checkbox)
156146
# FAVORITE = DefaultField(id=16, name="Favorite", type=CheckboxField.checkbox)
157147
BOOK = DefaultField(id=17, name="Book", type=FieldTypeEnum.TEXT_LINE)
158148
COMIC = DefaultField(id=18, name="Comic", type=FieldTypeEnum.TEXT_LINE)
159149
SERIES = DefaultField(id=19, name="Series", type=FieldTypeEnum.TEXT_LINE)
160150
MANGA = DefaultField(id=20, name="Manga", type=FieldTypeEnum.TEXT_LINE)
161151
SOURCE = DefaultField(id=21, name="Source", type=FieldTypeEnum.TEXT_LINE)
162-
DATE_UPLOADED = DefaultField(
163-
id=22, name="Date Uploaded", type=FieldTypeEnum.DATETIME
164-
)
165-
DATE_RELEASED = DefaultField(
166-
id=23, name="Date Released", type=FieldTypeEnum.DATETIME
167-
)
152+
DATE_UPLOADED = DefaultField(id=22, name="Date Uploaded", type=FieldTypeEnum.DATETIME)
153+
DATE_RELEASED = DefaultField(id=23, name="Date Released", type=FieldTypeEnum.DATETIME)
168154
VOLUME = DefaultField(id=24, name="Volume", type=FieldTypeEnum.TEXT_LINE)
169155
ANTHOLOGY = DefaultField(id=25, name="Anthology", type=FieldTypeEnum.TEXT_LINE)
170156
MAGAZINE = DefaultField(id=26, name="Magazine", type=FieldTypeEnum.TEXT_LINE)
171157
PUBLISHER = DefaultField(id=27, name="Publisher", type=FieldTypeEnum.TEXT_LINE)
172-
GUEST_ARTIST = DefaultField(
173-
id=28, name="Guest Artist", type=FieldTypeEnum.TEXT_LINE
174-
)
158+
GUEST_ARTIST = DefaultField(id=28, name="Guest Artist", type=FieldTypeEnum.TEXT_LINE)
175159
COMPOSER = DefaultField(id=29, name="Composer", type=FieldTypeEnum.TEXT_LINE)
176160
COMMENTS = DefaultField(id=30, name="Comments", type=FieldTypeEnum.TEXT_LINE)

tagstudio/src/core/library/alchemy/joins.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ class TagSubtag(Base):
1414
class TagField(Base):
1515
__tablename__ = "tag_fields"
1616

17-
field_id: Mapped[int] = mapped_column(
18-
ForeignKey("tag_box_fields.id"), primary_key=True
19-
)
17+
field_id: Mapped[int] = mapped_column(ForeignKey("tag_box_fields.id"), primary_key=True)
2018
tag_id: Mapped[int] = mapped_column(ForeignKey("tags.id"), primary_key=True)

0 commit comments

Comments
 (0)