From 96cd4929c9960cef1066ca472fcf6636d73cad07 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 11 Sep 2025 10:53:50 +0200 Subject: [PATCH] chore: Format files with ruff --- papis_extract/__init__.py | 1 - papis_extract/exporters/__init__.py | 1 - papis_extract/exporters/notes.py | 32 +++++++++++++++----------- papis_extract/extractors/__init__.py | 3 +-- papis_extract/extractors/pdf.py | 4 +--- papis_extract/extractors/pocketbook.py | 9 +++----- papis_extract/formatter.py | 1 + pyproject.toml | 19 ++++----------- 8 files changed, 29 insertions(+), 41 deletions(-) diff --git a/papis_extract/__init__.py b/papis_extract/__init__.py index 041a86a..ae04015 100644 --- a/papis_extract/__init__.py +++ b/papis_extract/__init__.py @@ -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 diff --git a/papis_extract/exporters/__init__.py b/papis_extract/exporters/__init__.py index b9980e5..7a1b343 100644 --- a/papis_extract/exporters/__init__.py +++ b/papis_extract/exporters/__init__.py @@ -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]] = {} diff --git a/papis_extract/exporters/notes.py b/papis_extract/exporters/notes.py index 29a2ed2..2a753d3 100644 --- a/papis_extract/exporters/notes.py +++ b/papis_extract/exporters/notes.py @@ -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. diff --git a/papis_extract/extractors/__init__.py b/papis_extract/extractors/__init__.py index da84829..b943913 100644 --- a/papis_extract/extractors/__init__.py +++ b/papis_extract/extractors/__init__.py @@ -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__) diff --git a/papis_extract/extractors/pdf.py b/papis_extract/extractors/pdf.py index 8caaf5c..887a88b 100644 --- a/papis_extract/extractors/pdf.py +++ b/papis_extract/extractors/pdf.py @@ -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) diff --git a/papis_extract/extractors/pocketbook.py b/papis_extract/extractors/pocketbook.py index ad73ad7..4f4b73a 100644 --- a/papis_extract/extractors/pocketbook.py +++ b/papis_extract/extractors/pocketbook.py @@ -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(" ") diff --git a/papis_extract/formatter.py b/papis_extract/formatter.py index 515a2c7..1bfd286 100644 --- a/papis_extract/formatter.py +++ b/papis_extract/formatter.py @@ -1,4 +1,5 @@ from typing import Protocol + from papis.document import Document from papis_extract.annotation import Annotation diff --git a/pyproject.toml b/pyproject.toml index ca3daf8..2988dd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]