Compare commits
2 commits
984025b472
...
5a99665d7e
Author | SHA1 | Date | |
---|---|---|---|
5a99665d7e | |||
aeb18ae358 |
3 changed files with 10 additions and 9 deletions
|
@ -8,10 +8,7 @@ import papis.strings
|
||||||
from papis.document import Document
|
from papis.document import Document
|
||||||
|
|
||||||
from papis_extract import extractor, exporter
|
from papis_extract import extractor, exporter
|
||||||
from papis_extract.formatter import (
|
from papis_extract.formatter import Formatter, formatters
|
||||||
Formatter,
|
|
||||||
formatters
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = papis.logging.get_logger(__name__)
|
logger = papis.logging.get_logger(__name__)
|
||||||
|
|
||||||
|
@ -68,6 +65,7 @@ def main(
|
||||||
write: bool,
|
write: bool,
|
||||||
template: str,
|
template: str,
|
||||||
git: bool,
|
git: bool,
|
||||||
|
force: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Extract annotations from any pdf document.
|
"""Extract annotations from any pdf document.
|
||||||
|
|
||||||
|
@ -89,7 +87,7 @@ def main(
|
||||||
|
|
||||||
formatter = formatters[template]
|
formatter = formatters[template]
|
||||||
|
|
||||||
run(documents, edit=manual, write=write, git=git, formatter=formatter)
|
run(documents, edit=manual, write=write, git=git, formatter=formatter, force=force)
|
||||||
|
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
|
@ -98,11 +96,12 @@ def run(
|
||||||
edit: bool = False,
|
edit: bool = False,
|
||||||
write: bool = False,
|
write: bool = False,
|
||||||
git: bool = False,
|
git: bool = False,
|
||||||
|
force: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
annotated_docs = extractor.start(documents)
|
annotated_docs = extractor.start(documents)
|
||||||
if write:
|
if write:
|
||||||
exporter.to_notes(
|
exporter.to_notes(
|
||||||
formatter=formatter, annotated_docs=annotated_docs, edit=edit, git=git
|
formatter=formatter, annotated_docs=annotated_docs, edit=edit, git=git, force=force
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
exporter.to_stdout(formatter=formatter, annotated_docs=annotated_docs)
|
exporter.to_stdout(formatter=formatter, annotated_docs=annotated_docs)
|
||||||
|
|
|
@ -67,7 +67,7 @@ def _add_annots_to_note(
|
||||||
:type formatted_annotations: list[str]
|
:type formatted_annotations: list[str]
|
||||||
:param git: Flag indicating whether to commit changes to git, defaults to False.
|
:param git: Flag indicating whether to commit changes to git, defaults to False.
|
||||||
:type git: bool, optional
|
:type git: bool, optional
|
||||||
:param force: Flag indicating whether to force adding annotations even if they
|
:param force: Flag indicating whether to force adding annotations even if they
|
||||||
already exist, defaults to False.
|
already exist, defaults to False.
|
||||||
:type force: bool, optional
|
:type force: bool, optional
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -26,13 +26,14 @@ def test_formatting_replacements(fmt_string, expected):
|
||||||
|
|
||||||
assert sut.format(fmt_string) == expected
|
assert sut.format(fmt_string) == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"fmt_string,expected",
|
"fmt_string,expected",
|
||||||
[
|
[
|
||||||
("{{doc.title}}", "document-title"),
|
("{{doc.title}}", "document-title"),
|
||||||
("{{doc.title}}-{{doc.author}}", "document-title-document-author"),
|
("{{doc.title}}-{{doc.author}}", "document-title-document-author"),
|
||||||
("{{quote}} ({{doc.author}})", "I am the text value (document-author)"),
|
("{{quote}} ({{doc.author}})", "I am the text value (document-author)"),
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
def test_formatting_document_access(fmt_string, expected):
|
def test_formatting_document_access(fmt_string, expected):
|
||||||
sut = Annotation(
|
sut = Annotation(
|
||||||
|
@ -40,10 +41,11 @@ def test_formatting_document_access(fmt_string, expected):
|
||||||
text="I am the text value",
|
text="I am the text value",
|
||||||
content="Whereas I represent the note",
|
content="Whereas I represent the note",
|
||||||
)
|
)
|
||||||
doc = Document(data= {"title": "document-title", "author": "document-author"})
|
doc = Document(data={"title": "document-title", "author": "document-author"})
|
||||||
|
|
||||||
assert sut.format(fmt_string, doc=doc) == expected
|
assert sut.format(fmt_string, doc=doc) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_colorname_matches_exact():
|
def test_colorname_matches_exact():
|
||||||
sut = Annotation("testfile", colors=(1.0, 0.0, 0.0), minimum_similarity_color=1.0)
|
sut = Annotation("testfile", colors=(1.0, 0.0, 0.0), minimum_similarity_color=1.0)
|
||||||
c_name = sut.colorname
|
c_name = sut.colorname
|
||||||
|
|
Loading…
Reference in a new issue