chore: Format files with ruff

This commit is contained in:
Marty Oehme 2025-09-11 10:53:50 +02:00
parent a854ef00d6
commit 96cd4929c9
Signed by: Marty
GPG key ID: 4E535BC19C61886E
8 changed files with 29 additions and 41 deletions

View file

@ -5,7 +5,6 @@ import papis.cli
import papis.config
import papis.document
import papis.logging
import papis.notes
import papis.strings
from papis.document import Document

View file

@ -4,7 +4,6 @@ from papis_extract.exporter import Exporter
from papis_extract.exporters.notes import NotesExporter
from papis_extract.exporters.stdout import StdoutExporter
logger = papis.logging.get_logger(__name__)
all_exporters: dict[str, type[Exporter]] = {}

View file

@ -1,14 +1,16 @@
from dataclasses import dataclass
import Levenshtein
from papis.document import Document
from papis_extract.annotation import Annotation
from papis_extract.formatter import Formatter
from papis.logging import get_logger
import papis.notes
import papis.commands.edit
import papis.config
import papis.document
import papis.git
import papis.config
import papis.commands.edit
import papis.notes
from papis.document import Document
from papis.logging import get_logger
from papis_extract.annotation import Annotation
from papis_extract.formatter import Formatter
logger = get_logger(__name__)
@ -33,7 +35,9 @@ class NotesExporter:
doc, annots, first=True
).split("\n")
if formatted_annotations:
self._add_annots_to_note(doc, formatted_annotations, duplicates=self.duplicates)
self._add_annots_to_note(
doc, formatted_annotations, duplicates=self.duplicates
)
if self.edit:
papis.commands.edit.edit_notes(doc, git=self.git)
@ -83,12 +87,12 @@ class NotesExporter:
# add newline if theres no empty space at file end
if len(existing) > 0 and existing[-1].strip() != "":
f.write("\n")
# FIXME this either joins them too close or moves them too far apart
# We need a better algorithm which knows what a full 'annotation' is.
f.write("\n\n".join(new_annotations))
# We filter out any empty lines from the annotations
filtered_annotations = [annot for annot in new_annotations if annot != ""]
f.write("\n\n".join(filtered_annotations))
logger.info(
f"Wrote {len(new_annotations)} "
f"{'line' if len(new_annotations) == 1 else 'lines'} "
f"Wrote {len(filtered_annotations)} "
f"{'line' if len(filtered_annotations) == 1 else 'lines'} "
f"to {papis.document.describe(document)}"
)
@ -106,7 +110,7 @@ class NotesExporter:
"""Returns the input annotations dropping any existing.
Takes a list of formatted annotations and a list of strings
(most probably existing lines in a file). If anny annotations
(most probably existing lines in a file). If any annotations
match an existing line closely enough, they will be dropped.
Returns list of annotations without duplicates.

View file

@ -3,9 +3,8 @@ from importlib.util import find_spec
import papis.logging
from papis_extract.extraction import Extractor
from papis_extract.extractors import pdf
from papis_extract.extractors import pdf, readera
from papis_extract.extractors.pocketbook import PocketBookExtractor
from papis_extract.extractors import readera
logger = papis.logging.get_logger(__name__)

View file

@ -32,9 +32,7 @@ class PdfExtractor:
annotations: list[Annotation] = []
try:
with mu.Document(filename) as doc:
for (
page
) in doc: # pyright: ignore [reportUnknownVariableType] - missing stub
for page in doc: # pyright: ignore [reportUnknownVariableType] - missing stub
annot: mu.Annot
for annot in page.annots():
quote, note = self._retrieve_annotation_content(page, annot)

View file

@ -44,16 +44,13 @@ class PocketBookExtractor:
annotations: list[Annotation] = []
for bm in html.select("div.bookmark"):
content = str(
(bm.select_one("div.bm-text>p") or html.new_string("")).text
or "" # pyright: ignore [reportUnknownArgumentType]
(bm.select_one("div.bm-text>p") or html.new_string("")).text or "" # pyright: ignore [reportUnknownArgumentType]
)
note = str(
(bm.select_one("div.bm-note>p") or html.new_string("")).text
or "" # pyright: ignore [reportUnknownArgumentType]
(bm.select_one("div.bm-note>p") or html.new_string("")).text or "" # pyright: ignore [reportUnknownArgumentType]
)
page = int(
(bm.select_one("p.bm-page") or html.new_string("")).text
or 0 # pyright: ignore [reportUnknownArgumentType]
(bm.select_one("p.bm-page") or html.new_string("")).text or 0 # pyright: ignore [reportUnknownArgumentType]
)
el_classes = bm.attrs.get("class", "").split(" ")

View file

@ -1,4 +1,5 @@
from typing import Protocol
from papis.document import Document
from papis_extract.annotation import Annotation

View file

@ -1,8 +1,6 @@
[project]
authors = [
{name = "Marty Oehme", email = "contact@martyoeh.me"},
]
license = {text = "GPL-3.0-or-later"}
authors = [{ name = "Marty Oehme", email = "contact@martyoeh.me" }]
license = { text = "GPL-3.0-or-later" }
requires-python = "<4.0,>=3.11"
dependencies = [
"pymupdf<2.0.0,>=1.24.2",
@ -35,18 +33,11 @@ repository = "https://github.com/marty-oehme/papis-extract"
extract = "papis_extract:main"
[project.optional-dependencies]
whoosh = [
"whoosh<3.0.0,>=2.7.4",
]
pocketbook = [
"beautifulsoup4<5.0.0,>=4.12.3",
]
whoosh = ["whoosh<3.0.0,>=2.7.4"]
pocketbook = ["beautifulsoup4<5.0.0,>=4.12.3"]
[tool.uv]
dev-dependencies = [
"pytest<9.0.0,>=8.0.0",
"pytest-cov<7.0.0,>=6.0.0",
]
dev-dependencies = ["pytest<9.0.0,>=8.0.0", "pytest-cov<7.0.0,>=6.0.0"]
[build-system]
requires = ["hatchling"]