Use Ruff for linting

This commit is contained in:
LuoShui 2024-12-09 16:56:10 +08:00
parent 6c2548f1ac
commit a0d89f7e1b
No known key found for this signature in database
GPG Key ID: 2C487F6F644C9EDB
7 changed files with 63 additions and 24 deletions

15
.pre-commit-config.yaml Normal file
View File

@ -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"

View File

@ -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"
@ -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"] }

View File

@ -1,20 +1,20 @@
from ._python_genshin_artifact import (
Artifact,
BuffInterface,
CalculatorConfig,
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,
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,
CalculatorConfig,
DamageResult,
DamageAnalysis,
)
__all__ = (

View File

@ -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

View File

@ -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,
)

View File

@ -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()
@ -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")

View File

@ -1,9 +1,9 @@
from python_genshin_artifact import (
CalculatorConfig,
get_damage_analysis,
CharacterInterface,
SkillInterface,
WeaponInterface,
get_damage_analysis,
)