Skip to content

Commit

Permalink
Merge pull request #25 from bpepple:devel
Browse files Browse the repository at this point in the history
Simple refactoring
  • Loading branch information
bpepple authored Feb 7, 2022
2 parents 8dda068 + fe526ae commit 9ffffb0
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 148 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ repos:
hooks:
- id: seed-isort-config
- repo: https://github.com/pycqa/isort
rev: 5.9.3
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 21.7b0
rev: 22.1.0
hooks:
- id: black
language_version: python3.8
Expand All @@ -17,7 +17,7 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.27.0
rev: v2.31.0
hooks:
- id: pyupgrade
args: ["--py36-plus", "--py37-plus", "--py38-plus"]
2 changes: 1 addition & 1 deletion darkseid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Projects version"""
__version__ = "1.1.0"
__version__ = "1.1.1"
15 changes: 7 additions & 8 deletions darkseid/comicarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,14 @@ def has_metadata(self) -> bool:
"""Checks to see if the archive has metadata"""

if self.has_md is None:
self.has_md = bool(
self.seems_to_be_a_comic_archive()
and (
not self.seems_to_be_a_comic_archive()
or self.ci_xml_filename in self.archiver.get_archive_filename_list()
)
)

if (
not self.seems_to_be_a_comic_archive()
or self.seems_to_be_a_comic_archive()
and self.ci_xml_filename not in self.archiver.get_archive_filename_list()
):
self.has_md = False
else:
self.has_md = True
return self.has_md

def apply_archive_info_to_metadata(
Expand Down
5 changes: 1 addition & 4 deletions darkseid/comicinfoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ def convert_xml_to_metadata(cls, tree: ET.ElementTree) -> GenericMetadata:
# Helper function
def xlate(tag: str) -> Optional[str]:
node = root.find(tag)
if node is not None:
return node.text
else:
return None
return node.text if node is not None else None

metadata.series = xlate("Series")
metadata.title = xlate("Title")
Expand Down
19 changes: 8 additions & 11 deletions darkseid/filenameparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def get_issue_count(self, filename: str, issue_end: int) -> str:
count = match.group()
found = True

if not found:
match = re.search(r"(?<=\(of\s)\d+(?=\))", tmpstr, re.IGNORECASE)
if match:
if match := re.search(r"(?<=\(of\s)\d+(?=\))", tmpstr, re.IGNORECASE):
if not found:
count = match.group()
found = True

Expand Down Expand Up @@ -100,9 +99,10 @@ def get_issue_number(self, filename: str) -> Tuple[str, int, int]:
# the same positions as original filename

# make a list of each word and its position
word_list: List[Tuple[str, int, int]] = []
for match in re.finditer(r"\S+", filename):
word_list.append((match.group(0), match.start(), match.end()))
word_list: List[Tuple[str, int, int]] = [
(match.group(0), match.start(), match.end())
for match in re.finditer(r"\S+", filename)
]

# remove the first word, since it can't be the issue number
if len(word_list) > 1:
Expand Down Expand Up @@ -177,17 +177,14 @@ def get_series_name(self, filename: str, issue_start: int) -> Tuple[str, str]:
series = re.sub(r"\(.*?\)", "", series)

# search for volume number
match = re.search(r"(.+)([vV]|[Vv][oO][Ll]\.?\s?)(\d+)\s*$", series)
if match:
if match := re.search(r"(.+)([vV]|[Vv][oO][Ll]\.?\s?)(\d+)\s*$", series):
series = match.group(1)
volume = match.group(3)

# if a volume wasn't found, see if the last word is a year in parentheses
# since that's a common way to designate the volume
if volume == "":
# match either (YEAR), (YEAR-), or (YEAR-YEAR2)
match = re.search(r"(\()(\d{4})(-(\d{4}|)|)(\))", last_word)
if match:
if match := re.search(r"(\()(\d{4})(-(\d{4}|)|)(\))", last_word):
volume = match.group(2)

series = series.strip()
Expand Down
8 changes: 2 additions & 6 deletions darkseid/genericmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,8 @@ def set_default_page_list(self, count: int) -> None:
self.pages.append(page_dict)

def get_archive_page_index(self, pagenum: int) -> int:
# convert the displayed page number to the page index of the file in
# the archive
if pagenum < len(self.pages):
return int(self.pages[pagenum]["Image"])
else:
return 0
# convert the displayed page number to the page index of the file in the archive
return int(self.pages[pagenum]["Image"]) if pagenum < len(self.pages) else 0

def get_cover_page_index_list(self) -> List[int]:
# return a list of archive page indices of cover pages
Expand Down
11 changes: 3 additions & 8 deletions darkseid/issuestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, text: str) -> None:
if isinstance(text, (int, float)):
text = str(text)

if text == "":
if not text:
return

# skip the minus sign if it's first
Expand Down Expand Up @@ -120,10 +120,7 @@ def as_float(self) -> Optional[float]:
:rtype: float, optional
"""
if self.suffix == "½":
if self.num is not None:
return self.num + 0.5
else:
return 0.5
return self.num + 0.5 if self.num is not None else 0.5
return self.num

def as_int(self) -> Optional[int]:
Expand All @@ -133,6 +130,4 @@ def as_int(self) -> Optional[int]:
:returns: String as an integer.
:rtype: int, optional
"""
if self.num is None:
return None
return int(self.num)
return None if self.num is None else int(self.num)
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Brian Pepple"

# The full version, including alpha/beta/rc tags
release = "1.1.0"
release = "1.1.1"


# -- General configuration ---------------------------------------------------
Expand Down
Loading

0 comments on commit 9ffffb0

Please sign in to comment.