Skip to content

Commit 9eefb50

Browse files
committed
add ruff and apply automatic fixes
1 parent 08cc2fc commit 9eefb50

File tree

14 files changed

+76
-50
lines changed

14 files changed

+76
-50
lines changed

pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,30 @@ rst-directives = [
142142
literal-inline-quotes = "double"
143143
type-checking-pydantic-enabled = true
144144

145+
[tool.ruff.per-file-ignores]
146+
"__init__.py" = ["F401", "F403"]
147+
"**/builders/*" = ["D101"]
148+
"tests/**" = ["D101"]
149+
150+
151+
[tool.ruff.lint]
152+
select = [
153+
# pycodestyle
154+
"E", "W293",
155+
# Pyflakes
156+
"F",
157+
# pep8-naming
158+
"N",
159+
# pydocstyle
160+
"D",
161+
]
162+
exclude = [
163+
"D105"
164+
]
165+
166+
167+
[tool.ruff.lint.pycodestyle]
168+
max-line-length = 120
169+
170+
[tool.ruff.lint.pep8-naming]
171+
extend-ignore-names = ["assert*"]

requirements-linting.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ flake8-simplify
1919
flake8-type-checking
2020
flake8-use-fstring
2121
flake8-secure-coding-standard
22-
22+
ruff

server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ async def get_auctions_history(
408408
@app.get("/auctions/{auction_id}", tags=["Char Bazaar"])
409409
async def get_auction(
410410
auction_id: int = Path(...),
411-
skip_details: bool = Query(False,
412-
description="Whether to skip the auction details and only fetch the basic information."),
411+
skip_details: bool = Query(
412+
False,
413+
description="Whether to skip the auction details and only fetch the basic information."
414+
),
413415
fetch_items: bool = Query(False, description="Whether to fetch additional item pages (if available)."),
414416
fetch_mounts: bool = Query(False, description="Whether to fetch additional mounts pages (if available)."),
415417
fetch_outfits: bool = Query(False, description="Whether to fetch additional outfits pages (if available)."),

tests/tests_enums.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import tibiapy.enums
12
from tests.tests_tibiapy import TestCommons
2-
from tibiapy.enums import *
33
from tibiapy.models import AuctionFilters
44

55

66
class TestEnums(TestCommons):
77

88
def test_numeric_enum_serialization(self):
9-
filters = AuctionFilters(battleye=AuctionBattlEyeFilter.INITIALLY_PROTECTED)
9+
filters = AuctionFilters(battleye=tibiapy.enums.AuctionBattlEyeFilter.INITIALLY_PROTECTED)
1010

1111
json_filters = filters.model_dump_json()
1212

@@ -17,12 +17,16 @@ def test_numeric_enum_deserialization(self):
1717

1818
filters = AuctionFilters.model_validate_json(json_filters)
1919

20-
self.assertEqual(filters.battleye, AuctionBattlEyeFilter.INITIALLY_PROTECTED)
20+
self.assertEqual(filters.battleye, tibiapy.enums.AuctionBattlEyeFilter.INITIALLY_PROTECTED)
2121

2222
def test_vocation_filter_from_name(self):
2323
"""Testing getting a HighscoresProfession entry from a vocation's name"""
24-
self.assertEqual(HighscoresProfession.KNIGHTS, HighscoresProfession.from_name("elite knight"))
25-
self.assertEqual(HighscoresProfession.KNIGHTS, HighscoresProfession.from_name("knight"))
26-
self.assertEqual(HighscoresProfession.KNIGHTS, HighscoresProfession.from_name("knights"))
27-
self.assertEqual(HighscoresProfession.ALL, HighscoresProfession.from_name("anything"))
28-
self.assertIsNone(HighscoresProfession.from_name("anything", all_fallback=False))
24+
self.assertEqual(tibiapy.enums.HighscoresProfession.KNIGHTS,
25+
tibiapy.enums.HighscoresProfession.from_name("elite knight"))
26+
self.assertEqual(tibiapy.enums.HighscoresProfession.KNIGHTS,
27+
tibiapy.enums.HighscoresProfession.from_name("knight"))
28+
self.assertEqual(tibiapy.enums.HighscoresProfession.KNIGHTS,
29+
tibiapy.enums.HighscoresProfession.from_name("knights"))
30+
self.assertEqual(tibiapy.enums.HighscoresProfession.ALL,
31+
tibiapy.enums.HighscoresProfession.from_name("anything"))
32+
self.assertIsNone(tibiapy.enums.HighscoresProfession.from_name("anything", all_fallback=False))

tests/tests_spell.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class TestSpell(TestCommons,):
1616
# region Spells Section Tests
17-
17+
1818
def test_spells_section_parser_from_content(self):
1919
"""Testing parsing a boosted creature"""
2020
content = self.load_resource(FILE_SPELLS_SECTION)
@@ -40,9 +40,9 @@ def test_spells_section_parser_from_content_unrelated_section(self):
4040

4141
with self.assertRaises(tibiapy.InvalidContent):
4242
SpellsSectionParser.from_content(content)
43-
43+
4444
# endregion
45-
45+
4646
# region Spells Tests
4747

4848
def test_spell_parser_from_content(self):
@@ -123,7 +123,8 @@ def test_spell_parser_from_content_revelation_perk(self):
123123
def test_spells_from_content_unknown_spell(self):
124124
"""Testing parsing an unknown spell
125125
126-
When trying to fetch a spell that doesn't exist, the website will just show the spells section."""
126+
When trying to fetch a spell that doesn't exist, the website will just show the spells section.
127+
"""
127128
content = self.load_resource(FILE_SPELLS_SECTION)
128129
spell = SpellParser.from_content(content)
129130

tibiapy/errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class EnumValueError(ValueError):
7373
def __init__(self, enum: Type[Enum], value: Any) -> None:
7474
self.enum = enum
7575
super().__init__(
76-
f"{value!r} is not a valid value for {enum.__name__}. Expected names ({self.names}) or values ({self.values})",
76+
f"{value!r} is not a valid value for {enum.__name__}."
77+
f"Expected names ({self.names}) or values ({self.values})",
7778
)
7879

7980
@property

tibiapy/parsers/guild.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def from_content(cls, content: str) -> Optional[Guild]:
111111
"""Create an instance of the class from the HTML content of the guild's page.
112112
113113
Parameters
114-
-----------
114+
----------
115115
The HTML content of the page.
116116
117117
Returns
118-
----------
118+
-------
119119
The guild contained in the page or None if it doesn't exist.
120120
121121
Raises
@@ -172,8 +172,7 @@ def _parse_current_member(cls, builder, previous_rank, values):
172172

173173
@classmethod
174174
def _parse_application_info(cls, builder, info_container):
175-
"""
176-
Parse the guild's application info.
175+
"""Parse the guild's application info.
177176
178177
Parameters
179178
----------
@@ -187,8 +186,7 @@ def _parse_application_info(cls, builder, info_container):
187186

188187
@classmethod
189188
def _parse_guild_disband_info(cls, builder: GuildBuilder, info_container: bs4.Tag):
190-
"""
191-
Parse the guild's disband info, if available.
189+
"""Parse the guild's disband info, if available.
192190
193191
Parameters
194192
----------
@@ -201,8 +199,7 @@ def _parse_guild_disband_info(cls, builder: GuildBuilder, info_container: bs4.Ta
201199

202200
@classmethod
203201
def _parse_guild_guildhall(cls, builder, info_container):
204-
"""
205-
Parse the guild's guildhall info.
202+
"""Parse the guild's guildhall info.
206203
207204
Parameters
208205
----------
@@ -234,8 +231,7 @@ def _parse_guild_homepage(cls, builder, info_container):
234231

235232
@classmethod
236233
def _parse_guild_info(cls, builder, info_container):
237-
"""
238-
Parse the guild's general information and applies the found values.
234+
"""Parse the guild's general information and applies the found values.
239235
240236
Parameters
241237
----------
@@ -271,8 +267,7 @@ def _parse_logo(cls, builder: GuildBuilder, parsed_content):
271267

272268
@classmethod
273269
def _parse_guild_members(cls, builder, parsed_content):
274-
"""
275-
Parse the guild's member and invited list.
270+
"""Parse the guild's member and invited list.
276271
277272
Parameters
278273
----------

tibiapy/parsers/highscores.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def _parse_entries_table(cls, builder: HighscoresBuilder, table):
9999

100100
@classmethod
101101
def _parse_filters_table(cls, builder, form):
102-
"""
103-
Parse the filters table found in a highscores page.
102+
"""Parse the filters table found in a highscores page.
104103
105104
Parameters
106105
----------
@@ -118,8 +117,7 @@ def _parse_filters_table(cls, builder, form):
118117

119118
@classmethod
120119
def _parse_tables(cls, parsed_content):
121-
"""
122-
Parse the information tables found in a highscores page.
120+
"""Parse the information tables found in a highscores page.
123121
124122
Parameters
125123
----------

tibiapy/parsers/house.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def _parse_filters(cls, builder: HousesSectionBuilder, form: bs4.Tag):
115115

116116
@classmethod
117117
def _parse_status(cls, builder: HouseEntryBuilder, status):
118-
"""
119-
Parse the status string found in the table and applies the corresponding values.
118+
"""Parse the status string found in the table and applies the corresponding values.
120119
121120
Parameters
122121
----------

tibiapy/parsers/kill_statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def from_content(cls, content: str) -> Optional[KillStatistics]:
1919
"""Create an instance of the class from the HTML content of the kill statistics' page.
2020
2121
Parameters
22-
-----------
22+
----------
2323
content:
2424
The HTML content of the page.
2525
2626
Returns
27-
----------
27+
-------
2828
The kill statistics contained in the page or None if it doesn't exist.
2929
3030
Raises

0 commit comments

Comments
 (0)