Skip to content

Commit

Permalink
Merge pull request #96
Browse files Browse the repository at this point in the history
* Update for Mokkari-3.0.0
* Drop support for Python-3.9
  • Loading branch information
bpepple authored Jan 29, 2024
1 parent 0129dd3 commit df57188
Show file tree
Hide file tree
Showing 17 changed files with 604 additions and 539 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.16
uses: JRubics/poetry-publish@v1.17
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os:
- ubuntu-latest
- macos-latest
Expand Down
2 changes: 1 addition & 1 deletion .idea/metron-tagger.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: seed-isort-config
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.3
rev: v0.1.14
hooks:
- id: ruff
- id: ruff-format
Expand Down
3 changes: 1 addition & 2 deletions metrontagger/duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from dataclasses import dataclass
from itertools import groupby
from pathlib import Path
from typing import Optional

import pandas as pd
import questionary
Expand All @@ -30,7 +29,7 @@ class Duplicates:

def __init__(self: "Duplicates", file_lst: list[Path]) -> None:
self._file_lst = file_lst
self._data_frame: Optional[pd.DataFrame] = None
self._data_frame: pd.DataFrame | None = None

def _image_hashes(self: "Duplicates") -> list[dict[str, any]]:
"""
Expand Down
11 changes: 5 additions & 6 deletions metrontagger/filerenamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import datetime
import re
from pathlib import Path
from typing import Optional

import questionary
from darkseid.issue_string import IssueString
Expand All @@ -20,8 +19,8 @@
class FileRenamer:
"""Class to rename a comic archive based on it's metadata tag"""

def __init__(self: "FileRenamer", metadata: Optional[Metadata] = None) -> None:
self.metadata: Optional[Metadata] = metadata
def __init__(self: "FileRenamer", metadata: Metadata | None = None) -> None:
self.metadata: Metadata | None = metadata
self.template: str = "%series% v%volume% #%issue% (of %issuecount%) (%year%)"
self.smart_cleanup: bool = True
self.issue_zero_padding: int = 3
Expand All @@ -43,7 +42,7 @@ def set_template(self: "FileRenamer", template: str) -> None:
"""
self.template = template

def replace_token(self: "FileRenamer", text: str, value: Optional[str], token: str) -> str:
def replace_token(self: "FileRenamer", text: str, value: str | None, token: str) -> str:
"""Method to replace a value with another value"""

# helper func
Expand Down Expand Up @@ -98,7 +97,7 @@ def smart_cleanup_string(self: "FileRenamer", new_name: str) -> str:
# remove duplicate spaces (again!)
return " ".join(new_name.split())

def determine_name(self: "FileRenamer", filename: Path) -> Optional[str]:
def determine_name(self: "FileRenamer", filename: Path) -> str | None:
"""Method to create the new filename based on the files metadata"""
md = self.metadata
new_name = self.template
Expand Down Expand Up @@ -172,7 +171,7 @@ def determine_name(self: "FileRenamer", filename: Path) -> Optional[str]:

return cleanup_string(new_name)

def rename_file(self: "FileRenamer", comic: Path) -> Optional[Path]:
def rename_file(self: "FileRenamer", comic: Path) -> Path | None:
# This shouldn't happen, but just in case let's make sure there is metadata.
if self.metadata is None:
questionary.print(
Expand Down
3 changes: 1 addition & 2 deletions metrontagger/filesorter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Class to sort comic file based on its metadata tags"""
from pathlib import Path
from shutil import Error, move
from typing import Optional

import questionary
from darkseid.comic import Comic
Expand All @@ -25,7 +24,7 @@ def __init__(self: "FileSorter", directory: str) -> None:
@staticmethod
def _cleanup_metadata(
meta_data: Metadata,
) -> tuple[Optional[str], Optional[str], Optional[str]]:
) -> tuple[str | None, str | None, str | None]:
"""Clean the metadata string."""
publisher = cleanup_string(meta_data.publisher.name)
series = cleanup_string(meta_data.series.name)
Expand Down
3 changes: 1 addition & 2 deletions metrontagger/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Optional

import questionary
from darkseid.comic import Comic
Expand Down Expand Up @@ -192,7 +191,7 @@ def _get_sort_dir(self: "Runner") -> bool:
def _get_duplicate_entry_index(
comic_path: str,
dups_list: list[DuplicateIssue],
) -> Optional[int]:
) -> int | None:
return next(
(idx for idx, item in enumerate(dups_list) if comic_path in item.path_),
None,
Expand Down
3 changes: 1 addition & 2 deletions metrontagger/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import platform
from os import environ
from pathlib import Path, PurePath
from typing import Optional

from xdg.BaseDirectory import save_config_path


class MetronTaggerSettings:
"""Class to handle project settings"""

def __init__(self: "MetronTaggerSettings", config_dir: Optional[str] = None) -> None:
def __init__(self: "MetronTaggerSettings", config_dir: str | None = None) -> None:
# Metron credentials
self.metron_user: str = ""
self.metron_pass: str = ""
Expand Down
24 changes: 12 additions & 12 deletions metrontagger/talker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
from datetime import datetime
from pathlib import Path
from typing import Optional

import mokkari
import questionary
Expand All @@ -10,7 +9,8 @@
from darkseid.metadata import Basic, Credit, Metadata, Role, Series
from imagehash import ImageHash, hex_to_hash, phash
from mokkari.exceptions import ApiError
from mokkari.issue import CreditsSchema, IssueSchema, RolesSchema
from mokkari.schemas.generic import GenericItem
from mokkari.schemas.issue import BaseIssue, Credit as MokkariCredit, Issue
from PIL import Image

from metrontagger import __version__
Expand All @@ -24,7 +24,7 @@
class MultipleMatch:
"""Class to hold information on searches with multiple matches"""

def __init__(self: "MultipleMatch", filename: Path, match_list: list[IssueSchema]) -> None:
def __init__(self: "MultipleMatch", filename: Path, match_list: list[BaseIssue]) -> None:
self.filename = filename
self.matches = match_list

Expand Down Expand Up @@ -53,7 +53,7 @@ def __init__(self: "Talker", username: str, password: str) -> None:
self.match_results = OnlineMatchResults()

@staticmethod
def _create_choice_list(match_set: list[IssueSchema]) -> list[questionary.Choice]:
def _create_choice_list(match_set: list[BaseIssue]) -> list[questionary.Choice]:
issue_lst = []
for i in match_set:
c = questionary.Choice(title=f"{i.issue_name} ({i.cover_date})", value=i.id)
Expand All @@ -65,8 +65,8 @@ def _create_choice_list(match_set: list[IssueSchema]) -> list[questionary.Choice
def _select_choice_from_matches(
self: "Talker",
fn: Path,
match_set: list[IssueSchema],
) -> Optional[int]:
match_set: list[BaseIssue],
) -> int | None:
"""
Function to ask user to choice which issue metadata to write,
when there are multiple choices
Expand All @@ -80,7 +80,7 @@ def _select_choice_from_matches(
return questionary.select("Select an issue to match", choices=choices).ask()

@staticmethod
def _get_comic_cover_hash(comic: Comic) -> Optional[ImageHash]:
def _get_comic_cover_hash(comic: Comic) -> ImageHash | None:
with Image.open(io.BytesIO(comic.get_page(0))) as img:
try:
ch = phash(img)
Expand All @@ -102,7 +102,7 @@ def _process_file(
self: "Talker",
fn: Path,
interactive: bool,
) -> tuple[Optional[int], bool]:
) -> tuple[int | None, bool]:
ca = Comic(str(fn))

if not ca.is_writable() and not ca.seems_to_be_a_comic_archive():
Expand Down Expand Up @@ -233,7 +233,7 @@ def retrieve_single_issue(self: "Talker", fn: Path, id_: int) -> None:
self._write_issue_md(fn, id_)

@staticmethod
def _map_resp_to_metadata(resp: IssueSchema) -> Metadata: # C901
def _map_resp_to_metadata(resp: Issue) -> Metadata: # C901
# Helper functions
def create_resource_list(resource: any) -> list[Basic]:
return [Basic(r.name, r.id) for r in resource]
Expand All @@ -247,9 +247,9 @@ def create_note(issue_id: int) -> str:

def add_credits_to_metadata(
meta_data: Metadata,
credits_resp: list[CreditsSchema],
credits_resp: list[MokkariCredit],
) -> Metadata:
def create_role_list(roles: list[RolesSchema]) -> list[Role]:
def create_role_list(roles: list[GenericItem]) -> list[Role]:
return [Role(r.name, r.id) for r in roles]

for c in credits_resp:
Expand Down Expand Up @@ -298,6 +298,6 @@ def map_ratings(rating: str) -> str:
if resp.rating:
md.age_rating = map_ratings(resp.rating.name)
if resp.resource_url:
md.web_link = resp.resource_url
md.web_link = str(resp.resource_url)

return md
3 changes: 1 addition & 2 deletions metrontagger/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Some miscellaneous functions"""
from pathlib import Path
from typing import Optional
from urllib.parse import quote_plus

from darkseid.filename import FileNameParser


def cleanup_string(path_name: Optional[str]) -> Optional[str]:
def cleanup_string(path_name: str | None) -> str | None:
"""
Function to remove some characters that don't play nicely on Windows machines filesystem
"""
Expand Down
3 changes: 1 addition & 2 deletions metrontagger/validate_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from importlib.resources import as_file, files
from io import BytesIO
from pathlib import Path
from typing import Optional

from lxml import etree as et

Expand All @@ -22,7 +21,7 @@ def __init__(self: "ValidateComicInfo", ci_xml: bytes) -> None:
self.comic_info_xml = ci_xml

@staticmethod
def _get_xsd(schema_version: SchemaVersion) -> Optional[Path]:
def _get_xsd(schema_version: SchemaVersion) -> Path | None:
"""Method to return path of CI Schema."""
if schema_version == SchemaVersion.v1:
with as_file(files("metrontagger.schema.v1").joinpath("ComicInfo.xsd")) as xsd:
Expand Down
Loading

0 comments on commit df57188

Please sign in to comment.