format with ruff
Some checks failed
ci/woodpecker/push/tests Pipeline failed

Signed-off-by: Ivan Schaller <ivan@schaller.sh>
This commit is contained in:
Ivan Schaller 2023-02-18 12:29:25 +01:00
parent 2ad0c575a7
commit 5e28cb1088
Signed by: olofvndrhr
GPG key ID: 2A6BE07D99C8C205
12 changed files with 27 additions and 38 deletions

View file

@ -3,7 +3,8 @@
class YourAPI:
"""Your API Class.
Get infos for a manga from example.org
Get infos for a manga from example.org.
Args:
url_uuid (str): URL or UUID of the manga
@ -23,9 +24,7 @@ class YourAPI:
img_base_url = "https://uploads.mangadex.org"
def __init__(self, url_uuid, language, forcevol):
"""
get infos to initiate class
"""
"""get infos to initiate class."""
self.api_name = "Your API Name"
self.url_uuid = url_uuid
@ -67,8 +66,7 @@ class YourAPI:
}
def get_chapter_images(chapter: str, download_wait: float) -> list:
"""
Get chapter images as a list (full links)
"""Get chapter images as a list (full links).
Args:
chapter: The chapter number (chapter data index)
@ -77,7 +75,6 @@ class YourAPI:
Returns:
The list of urls of the page images
"""
# example
return [
"https://abc.def/image/123.png",
@ -85,10 +82,10 @@ class YourAPI:
"https://abc.def/image/12345.png",
]
def create_metadata(self, chapter: str) -> dict:
"""
Get metadata with correct keys for ComicInfo.xml
Provide as much metadata as possible. empty/false values will be ignored
def create_metadata(chapter: str) -> dict:
"""Get metadata with correct keys for ComicInfo.xml.
Provide as much metadata as possible. empty/false values will be ignored.
Args:
chapter: The chapter number (chapter data index)
@ -96,7 +93,6 @@ class YourAPI:
Returns:
The metadata as a dict
"""
# metadata types. have to be valid
# {key: (type, default value, valid values)}
{

View file

@ -9,7 +9,8 @@ from mangadlp import utils
class Mangadex:
"""Mangadex API Class.
Get infos for a manga from mangadex.org
Get infos for a manga from mangadex.org.
Args:
url_uuid (str): URL or UUID of the manga

View file

@ -14,7 +14,7 @@ from mangadlp.utils import get_file_format
def match_api(url_uuid: str) -> type:
"""Match the correct api class from a string
"""Match the correct api class from a string.
Args:
url_uuid: url/uuid to check
@ -22,7 +22,6 @@ def match_api(url_uuid: str) -> type:
Returns:
The class of the API to use
"""
# apis to check
apis: list[tuple[str, re.Pattern, type]] = [
(
@ -53,6 +52,7 @@ def match_api(url_uuid: str) -> type:
class MangaDLP:
"""Download Mangas from supported sites.
After initialization, start the script with the function get_manga().
Args:

View file

@ -228,11 +228,7 @@ def readin_list(_ctx, _param, value) -> list:
)
@click.pass_context
def main(ctx: click.Context, **kwargs) -> None:
"""
Script to download mangas from various sites
"""
"""Script to download mangas from various sites."""
url_uuid: str = kwargs.pop("url_uuid")
read_mangas: list[str] = kwargs.pop("read_mangas")
verbosity: int = kwargs.pop("verbosity")

View file

@ -5,7 +5,10 @@ from loguru import logger as log
def run_hook(command: str, hook_type: str, **kwargs) -> int:
"""
"""Run a command.
Run a command with subprocess.run and add kwargs to the environment.
Args:
command (str): command to run
hook_type (str): type of the hook
@ -14,7 +17,6 @@ def run_hook(command: str, hook_type: str, **kwargs) -> int:
Returns:
exit_code (int): exit code of command
"""
# check if hook commands are empty
if not command or command == "None":
log.debug(f"Hook '{hook_type}' empty. Not running")

View file

@ -8,9 +8,7 @@ LOGURU_FMT = "{time:%Y-%m-%dT%H:%M:%S%z} | <level>[{level: <7}]</level> [{name:
# from loguru docs
class InterceptHandler(logging.Handler):
"""
Intercept python logging messages and log them via loguru.logger
"""
"""Intercept python logging messages and log them via loguru.logger."""
def emit(self, record):
# Get corresponding Loguru level if it exists

View file

@ -84,7 +84,7 @@ def validate_metadata(metadata_in: dict) -> Dict[str, dict]:
# check if metadata type is correct
log.debug(f"Key:{key} -> value={type(md_to_check)} -> check={metadata_type}")
if not isinstance(md_to_check, metadata_type): # noqa
if not isinstance(md_to_check, metadata_type):
log.warning(
f"Metadata has wrong type: {key}:{metadata_type} -> {md_to_check}"
)

View file

@ -16,8 +16,6 @@ def test_read_and_url():
def test_no_read_and_url():
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
link_file = "tests/testfile.txt"
language = "en"
chapters = "1"
file_format = "cbz"
@ -30,7 +28,6 @@ def test_no_read_and_url():
def test_no_chaps():
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
language = "en"
chapters = ""
file_format = "cbz"
download_path = "tests"
command_args = f"-u {url_uuid} -l {language} --path {download_path} --format {file_format} --debug"

View file

@ -40,7 +40,7 @@ def test_manga_pre_hook(wait_10s):
manga_pre_hook,
]
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert hook_file.is_file()
@ -72,7 +72,7 @@ def test_manga_post_hook(wait_10s):
manga_post_hook,
]
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert hook_file.is_file()
@ -104,7 +104,7 @@ def test_chapter_pre_hook(wait_10s):
chapter_pre_hook,
]
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert hook_file.is_file()
@ -136,7 +136,7 @@ def test_chapter_post_hook(wait_10s):
chapter_post_hook,
]
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert hook_file.is_file()
@ -176,7 +176,7 @@ def test_all_hooks(wait_10s):
chapter_post_hook,
]
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert Path("tests/manga-pre2.txt").is_file()

View file

@ -6,7 +6,7 @@ from mangadlp.cache import CacheDB
def test_cache_creation():
cache_file = Path("cache.json")
cache = CacheDB(cache_file, "abc", "en", "test")
CacheDB(cache_file, "abc", "en", "test")
assert cache_file.exists()
cache_file.unlink()

View file

@ -133,7 +133,7 @@ def test_metadata_chapter_validity(wait_20s):
schema = xmlschema.XMLSchema("mangadlp/metadata/ComicInfo_v2.0.xsd")
script_path = "manga-dlp.py"
command = ["python3", script_path] + command_args
command = ["python3", script_path, *command_args]
assert subprocess.call(command) == 0
assert metadata_path.is_file()

View file

@ -56,7 +56,7 @@ def test_alt_title_fallback():
forcevol = False
test = Mangadex(url_uuid, language, forcevol)
assert test.manga_title == "Iruma à lécole des démons"
assert test.manga_title == "Iruma à l`école des démons"
def test_chapter_infos():
@ -206,7 +206,6 @@ def test_get_chapter_images():
test = Mangadex(url_uuid, language, forcevol)
img_base_url = "https://uploads.mangadex.org"
chapter_hash = "0752bc5db298beff6b932b9151dd8437"
chapter_uuid = "e86ec2c4-c5e4-4710-bfaa-7604f00939c7"
chapter_num = "1"
test_list = [
f"{img_base_url}/data/{chapter_hash}/x1-0deb4c9bfedd5be49e0a90cfb17cf343888239898c9e7451d569c0b3ea2971f4.jpg",