Skip to content

Commit

Permalink
✨ Use Ruff for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
luoshuijs committed Dec 9, 2024
1 parent 6c2548f commit a0d89f7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 23 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.10
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
ci:
autofix_commit_msg: ":art: [pre-commit.ci] Auto format from pre-commit.com hooks"
autoupdate_commit_msg: ":arrow_up: [pre-commit.ci] pre-commit autoupdate"
26 changes: 25 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ bindings = "pyo3"
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[dependency-groups]
linting = [
'ruff',
]

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "INFO"
Expand All @@ -53,4 +58,23 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
[tool.black]
include = '\.pyi?$'
line-length = 120
target-version = ["py38"]
target-version = ["py38"]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
extend-select = [
"Q", # flake8-quotes
"C90", # complex-structure
"I", # isort
"F", # pyflakes
"B", # flake8-bugbear
"C4", # flake8-comprehensions
]
extend-ignore = [
"E721", # using type() instead of isinstance() - we use this in tests
]
mccabe = { max-complexity = 13 }
isort = { known-first-party = ["python_genshin_artifact", "tests"] }

26 changes: 13 additions & 13 deletions python_genshin_artifact/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from ._python_genshin_artifact import (
get_damage_analysis,
get_transformative_damage,
gen_character_meta_as_json,
gen_weapon_meta_as_json,
gen_artifact_meta_as_json,
gen_generate_locale_as_json,
TransformativeDamage,
CharacterInterface,
WeaponInterface,
BuffInterface,
Artifact,
SkillInterface,
EnemyInterface,
BuffInterface,
CalculatorConfig,
DamageResult,
CharacterInterface,
DamageAnalysis,
DamageResult,
EnemyInterface,
SkillInterface,
TransformativeDamage,
WeaponInterface,
gen_artifact_meta_as_json,
gen_character_meta_as_json,
gen_generate_locale_as_json,
gen_weapon_meta_as_json,
get_damage_analysis,
get_transformative_damage,
)

__all__ = (
Expand Down
2 changes: 1 addition & 1 deletion python_genshin_artifact/_python_genshin_artifact.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import List, Optional, Tuple, TYPE_CHECKING, Dict, final
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, final

if sys.version_info < (3, 11):
from typing_extensions import Literal
Expand Down
6 changes: 3 additions & 3 deletions python_genshin_artifact/assets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from typing import Dict, Tuple, List
from typing import Dict, List, Tuple

from python_genshin_artifact import (
gen_character_meta_as_json,
gen_weapon_meta_as_json,
gen_artifact_meta_as_json,
gen_character_meta_as_json,
gen_generate_locale_as_json,
gen_weapon_meta_as_json,
)


Expand Down
8 changes: 4 additions & 4 deletions python_genshin_artifact/enka/enka_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import re
from typing import Tuple, List, Optional
from typing import List, Optional, Tuple

from python_genshin_artifact import Artifact, CharacterInterface, WeaponInterface
from python_genshin_artifact.enka.artifacts import artifacts_name_map, equip_type_map
from python_genshin_artifact.enka.assets import Assets
from python_genshin_artifact.enka.characters import characters_map
from python_genshin_artifact.enka.fight import fight_map, to_float
from python_genshin_artifact.enka.weapon import weapon_name_map
from python_genshin_artifact.error import EnkaParseException
from python_genshin_artifact import Artifact, CharacterInterface, WeaponInterface

assets = Assets()

Expand Down Expand Up @@ -75,8 +75,8 @@ def de_equip_list(equip_list: list[dict]) -> Tuple[WeaponInterface, List[Artifac
_flat = _equip["flat"]
try:
artifact_id = int(re.findall(r"\d+", _flat["icon"])[0])
except IndexError:
raise EnkaParseException(f"artifact_id is not found in {_flat['icon']}")
except IndexError as exc:
raise EnkaParseException(f"artifact_id is not found in {_flat['icon']}") from exc
set_name = artifacts_name_map.get(artifact_id)
if set_name is None:
raise EnkaParseException(f"artifact_id={artifact_id} is not found in assets")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_damage_calculator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from python_genshin_artifact import (
CalculatorConfig,
get_damage_analysis,
CharacterInterface,
SkillInterface,
WeaponInterface,
get_damage_analysis,
)


Expand Down

0 comments on commit a0d89f7

Please sign in to comment.