Compare commits

..

1 commit

Author SHA1 Message Date
22d762f86e
fix: Respect minimum color similarity option
Some checks failed
ci/woodpecker/manual/lint Pipeline failed
ci/woodpecker/manual/static_analysis Pipeline failed
ci/woodpecker/manual/test Pipeline failed
Previously we would always assign a minimum color similarity of 1.0,
regardless of the option set. Now we set a minimum similarity according
to the option set in the configuration, otherwise the default set for
that option and fall back to a simple default value declared at the top
of the file.
2024-11-30 21:22:45 +01:00
4 changed files with 12 additions and 13 deletions

View file

@ -3,7 +3,7 @@ steps:
image: nikolaik/python-nodejs
commands:
- npm install --global pyright
- uv sync
- python --version && uv version && pyright --version
- poetry install
- python --version && poetry --version && pyright --version
- echo "------------- running pyright typecheck -------------"
- uv run pyright
- poetry run pyright

View file

@ -3,9 +3,9 @@ when:
steps:
pytest:
image: nikolaik/python-nodejs
image: ghcr.io/withlogicco/poetry:1.5.1
commands:
- uv sync
- python --version && uv version
- poetry install
- python --version && poetry --version
- echo "------------- running pytest -------------"
- uv run pytest
- poetry run pytest

View file

@ -37,17 +37,12 @@ class Annotation:
page: int = 0,
tag: str = "",
type: str = "Highlight",
minimum_similarity_color: float | None = None,
) -> None:
self.file = file
self._color = color
self.content = content
self.note = note
self.page = page
self.minimum_similarity_color = minimum_similarity_color or (
papis.config.getfloat("minimum_similarity_color", "plugins.extract")
or COLOR_SIMILARITY_MINIMUM_FALLBACK
)
self.tag = tag or self._tag_from_colorname(self.colorname or "")
self.type = type
@ -87,7 +82,10 @@ class Annotation:
"""
annot_colors = self.color or (0.0, 0.0, 0.0)
nearest = None
minimum_similarity = self.minimum_similarity_color
minimum_similarity = (
papis.config.getfloat("minimum_similarity_color", "plugins.extract")
or COLOR_SIMILARITY_MINIMUM_FALLBACK
)
for name, values in COLORS.items():
similarity_ratio = self._color_similarity_ratio(values, annot_colors)
if similarity_ratio >= minimum_similarity:

View file

@ -35,6 +35,7 @@ class PdfExtractor:
for (
page
) in doc: # pyright: ignore [reportUnknownVariableType] - missing stub
page = cast(mu.Page, page)
annot: mu.Annot
for annot in page.annots():
quote, note = self._retrieve_annotation_content(page, annot)