From 0dc7e2f60df39a2a947c2576b821efd675e0ba90 Mon Sep 17 00:00:00 2001 From: olofvndrhr Date: Wed, 21 Feb 2024 13:31:48 +0100 Subject: [PATCH] update ruff settings and fix lint violations --- contrib/api_template.py | 8 ++--- justfile | 42 +++++++++++++------------- pyproject.toml | 57 +++++++++++++++++++++++------------ tests/test_03_downloader.py | 3 +- tests/test_04_input.py | 2 +- tests/test_11_api_mangadex.py | 10 +++--- tests/test_21_full.py | 3 +- 7 files changed, 72 insertions(+), 53 deletions(-) diff --git a/contrib/api_template.py b/contrib/api_template.py index 0ee4293..2a6e83c 100644 --- a/contrib/api_template.py +++ b/contrib/api_template.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Union +from typing import Dict, List from mangadlp.models import ChapterData, ComicInfo @@ -40,7 +40,7 @@ class YourAPI: self.manga_uuid = "abc" self.manga_title = "abc" self.chapter_list = ["1", "2", "2.1", "5", "10"] - self.manga_chapter_data: dict[str, ChapterData] = { # example data + self.manga_chapter_data: Dict[str, ChapterData] = { # example data "1": { "uuid": "abc", "volume": "1", @@ -57,7 +57,7 @@ class YourAPI: }, } # or with --forcevol - self.manga_chapter_data: dict[str, ChapterData] = { + self.manga_chapter_data: Dict[str, ChapterData] = { "1:1": { "uuid": "abc", "volume": "1", @@ -72,7 +72,7 @@ class YourAPI: }, } - def get_chapter_images(self, chapter: str, wait_time: float) -> list[str]: + def get_chapter_images(self, chapter: str, wait_time: float) -> List[str]: """Get chapter images as a list (full links). Args: diff --git a/justfile b/justfile index 9e80585..eb9590e 100755 --- a/justfile +++ b/justfile @@ -6,7 +6,7 @@ set shell := ["bash", "-uc"] set dotenv-load show_receipts: - @just --list + just --list show_system_info: @echo "==================================" @@ -18,58 +18,58 @@ show_system_info: @echo "==================================" setup: - @asdf install - @lefthook install + asdf install + lefthook install create_venv: @echo "creating venv" - @python3 -m pip install --upgrade pip setuptools wheel - @python3 -m venv venv + python3 -m pip install --upgrade pip setuptools wheel + python3 -m venv venv install_deps: @echo "installing dependencies" - @python3 -m hatch dep show requirements --project-only > /tmp/requirements.txt - @pip3 install -r /tmp/requirements.txt + python3 -m hatch dep show requirements --project-only > /tmp/requirements.txt + pip3 install -r /tmp/requirements.txt install_deps_dev: @echo "installing dev dependencies" - @python3 -m hatch dep show requirements --project-only > /tmp/requirements.txt - @python3 -m hatch dep show requirements --env-only >> /tmp/requirements.txt - @pip3 install -r /tmp/requirements.txt + python3 -m hatch dep show requirements --project-only > /tmp/requirements.txt + python3 -m hatch dep show requirements --env-only >> /tmp/requirements.txt + pip3 install -r /tmp/requirements.txt create_reqs: @echo "creating requirements" - @pipreqs --force --savepath requirements.txt src/mangadlp/ + pipreqs --force --savepath requirements.txt src/mangadlp/ test_shfmt: - @find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -d -i 4 -bn -ci -sr "{}" \+; + find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -d -i 4 -bn -ci -sr "{}" \+; format_shfmt: - @find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -w -i 4 -bn -ci -sr "{}" \+; + find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -w -i 4 -bn -ci -sr "{}" \+; lint: just show_system_info just test_shfmt - @hatch run lint:style - @hatch run lint:typing + hatch run lint:style + hatch run lint:typing format: just show_system_info just format_shfmt - @hatch run lint:fmt + hatch run lint:fmt check: - just format just lint + just format test: - @hatch run default:test + hatch run default:test coverage: - @hatch run default:cov + hatch run default:cov build: - @hatch build --clean + hatch build --clean run loglevel *flags: - @hatch run mangadlp --loglevel {{loglevel}} {{flags}} + hatch run mangadlp --loglevel {{loglevel}} {{flags}} diff --git a/pyproject.toml b/pyproject.toml index 79ab6d4..345f573 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,18 +45,18 @@ source = "regex_commit" path = "src/mangadlp/__about__.py" tag_sign = false -[tool.hatch.build] -ignore-vcs = true - [tool.hatch.build.targets.sdist] packages = ["src/mangadlp"] [tool.hatch.build.targets.wheel] packages = ["src/mangadlp"] +### ### envs +### [tool.hatch.envs.default] +python = "3.11" dependencies = [ "pytest==7.4.3", "coverage==7.3.2", @@ -76,17 +76,26 @@ python = ["3.8", "3.9", "3.10", "3.11"] [tool.hatch.envs.lint] detached = true dependencies = [ - "mypy==1.7.1", - "ruff==0.1.7", + "mypy==1.8.0", + "ruff==0.2.2", ] [tool.hatch.envs.lint.scripts] typing = "mypy --non-interactive --install-types {args:src/mangadlp}" -style = ["ruff check --diff {args:src/mangadlp}", "ruff format --check --diff {args:src/mangadlp}"] -fmt = ["ruff format {args:src/mangadlp}", "ruff check --fix {args:src/mangadlp}", "style"] +style = [ + "ruff check --diff {args:.}", + "ruff format --check --diff {args:.}" +] +fmt = [ + "ruff check --fix {args:.}", + "ruff format {args:.}", + "style" +] all = ["style", "typing"] +### ### ruff +### [tool.ruff] target-version = "py38" @@ -94,7 +103,6 @@ line-length = 100 indent-width = 4 fix = true show-fixes = true -ignore-init-module-imports = true respect-gitignore = true src = ["src", "tests"] exclude = [ @@ -112,6 +120,7 @@ exclude = [ "dist", "node_modules", "venv", + "contrib" ] [tool.ruff.lint] @@ -142,6 +151,7 @@ select = [ "W", "YTT", ] +ignore-init-module-imports = true ignore = ["E501", "D103", "D100", "D102", "PLR2004", "D403", "ISC001", "FBT001", "FBT002", "FBT003", "W505"] unfixable = ["F401"] @@ -150,39 +160,42 @@ quote-style = "double" indent-style = "space" skip-magic-trailing-comma = false line-ending = "lf" +docstring-code-format = true -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = ["D104"] "__about__.py" = ["D104", "F841"] -"tests/**/*" = ["PLR2004", "S101", "TID252"] +"tests/**/*" = ["PLR2004", "S101", "TID252", "T201", "ARG001", "S603", "S605"] -[tool.ruff.pyupgrade] +[tool.ruff.lint.pyupgrade] keep-runtime-typing = true -[tool.ruff.isort] +[tool.ruff.lint.isort] lines-after-imports = 2 known-first-party = ["mangadlp"] -[tool.ruff.flake8-tidy-imports] +[tool.ruff.lint.flake8-tidy-imports] ban-relative-imports = "all" -[tool.ruff.pylint] +[tool.ruff.lint.pylint] max-branches = 24 max-returns = 12 max-statements = 100 max-args = 15 allow-magic-value-types = ["str", "bytes", "complex", "float", "int"] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 15 -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" -[tool.ruff.pycodestyle] +[tool.ruff.lint.pycodestyle] max-doc-length = 100 +### ### mypy +### [tool.mypy] #plugins = ["pydantic.mypy"] @@ -204,16 +217,20 @@ show_error_context = true #init_typed = true #warn_required_dynamic_aliases = true +### ### pytest +### + [tool.pytest.ini_options] pythonpath = ["src"] addopts = "--color=yes --exitfirst --verbose -ra" -#addopts = "--color=yes --exitfirst --verbose -ra --capture=tee-sys" filterwarnings = [ 'ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning', ] +### ### coverage +### [tool.coverage.run] source_pkgs = ["mangadlp", "tests"] @@ -222,8 +239,8 @@ parallel = true omit = ["src/mangadlp/__about__.py"] [tool.coverage.paths] -testproj = ["src/mangadlp", "*/mangadlp/src/mangadlp"] -tests = ["tests", "*/mangadlp/tests"] +testproj = ["src/mangadlp", "*/manga-dlp/src/mangadlp"] +tests = ["tests", "*/manga-dlp/tests"] [tool.coverage.report] # Regexes for lines to exclude from consideration diff --git a/tests/test_03_downloader.py b/tests/test_03_downloader.py index e502111..c06d38e 100644 --- a/tests/test_03_downloader.py +++ b/tests/test_03_downloader.py @@ -1,5 +1,6 @@ import shutil from pathlib import Path +from typing import List import pytest import requests @@ -18,7 +19,7 @@ def test_downloader(): ] chapter_path = Path("tests/test_folder1") chapter_path.mkdir(parents=True, exist_ok=True) - images: list[str] = [] + images: List[str] = [] downloader.download_chapter(urls, str(chapter_path), 2) for file in chapter_path.iterdir(): images.append(file.name) diff --git a/tests/test_04_input.py b/tests/test_04_input.py index 3c332d1..969e152 100644 --- a/tests/test_04_input.py +++ b/tests/test_04_input.py @@ -52,7 +52,7 @@ def test_no_volume(): def test_readin_list(): list_file = "tests/test_list.txt" - test_list = mdlpinput.readin_list(None, None, list_file) + test_list = mdlpinput.readin_list(None, None, list_file) assert test_list == [ "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu", diff --git a/tests/test_11_api_mangadex.py b/tests/test_11_api_mangadex.py index 793a1a0..64e8a68 100644 --- a/tests/test_11_api_mangadex.py +++ b/tests/test_11_api_mangadex.py @@ -389,11 +389,11 @@ def test_chapter_metadata(): forcevol = False test = Mangadex(url_uuid, language, forcevol) chapter_metadata = test.create_metadata("1") - manga_name = chapter_metadata["Series"] - chapter_name = chapter_metadata["Title"] - chapter_num = chapter_metadata["Number"] - chapter_volume = chapter_metadata["Volume"] - chapter_url = chapter_metadata["Web"] + manga_name = chapter_metadata["Series"] + chapter_name = chapter_metadata["Title"] + chapter_num = chapter_metadata["Number"] + chapter_volume = chapter_metadata["Volume"] + chapter_url = chapter_metadata["Web"] assert (manga_name, chapter_name, chapter_volume, chapter_num, chapter_url) == ( "Komi-san wa Komyushou Desu", diff --git a/tests/test_21_full.py b/tests/test_21_full.py index ee7765f..c30726d 100644 --- a/tests/test_21_full.py +++ b/tests/test_21_full.py @@ -3,6 +3,7 @@ import platform import shutil import time from pathlib import Path +from typing import List import pytest from pytest import MonkeyPatch @@ -165,7 +166,7 @@ def test_full_with_input_skip_folder(wait_10s: MonkeyPatch): chapter_path.mkdir(parents=True, exist_ok=True) os.system(f"python3 {script_path} {command_args}") - found_files: list[str] = [] + found_files: List[str] = [] for file in chapter_path.iterdir(): found_files.append(file.name)