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.config
import papis.document import papis.document
import papis.logging import papis.logging
import papis.notes
import papis.strings import papis.strings
from papis.document import Document 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.notes import NotesExporter
from papis_extract.exporters.stdout import StdoutExporter from papis_extract.exporters.stdout import StdoutExporter
logger = papis.logging.get_logger(__name__) logger = papis.logging.get_logger(__name__)
all_exporters: dict[str, type[Exporter]] = {} all_exporters: dict[str, type[Exporter]] = {}

View file

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

View file

@ -3,9 +3,8 @@ from importlib.util import find_spec
import papis.logging import papis.logging
from papis_extract.extraction import Extractor 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.pocketbook import PocketBookExtractor
from papis_extract.extractors import readera
logger = papis.logging.get_logger(__name__) logger = papis.logging.get_logger(__name__)

View file

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

View file

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

View file

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

View file

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