Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ovld display exception with ExtendAttr class #46

Open
wants to merge 1 commit into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions paperoni/cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ class ExtendAttr():
def __init__(self, search_result) -> None:
self._search_result = search_result

# TODO: make this class fake it's type so it works with the Ovld package
@property
def __class__(self):
return self._search_result.__class__

def __getattribute__(self, __name: str) -> Any:
try:
attr = super().__getattribute__(__name)
Expand Down Expand Up @@ -250,6 +255,7 @@ def query_papers(
# [negate]
allow_download: Option & bool = True,
):
excerpt = r"[^\w](Milaâ?|Quebec AI Institute|Montreal Institute for Learning Algorithms|Québec AI Institute Université de Montréal)[^\w]"
yield from search(
title=title,
author=author,
Expand Down
6 changes: 6 additions & 0 deletions paperoni/db/model_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ovld import ovld

from ..cli_helper import ExtendAttr
from .. import model as M
from . import schema as sch

Expand Down Expand Up @@ -86,3 +87,8 @@ def export(venue: sch.Venue):
volume=venue.volume,
quality=venue.quality,
)


@ovld
def export(extattr: ExtendAttr):
return export(extattr._search_result)
14 changes: 12 additions & 2 deletions paperoni/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from hrepr import H
from ovld import ovld

from .cli_helper import ExtendAttr
from .db import schema as sch
from .model import Author, DatePrecision, Paper, Venue, from_dict

Expand Down Expand Up @@ -91,7 +92,7 @@ def display(d: dict):


@ovld
def display(paper: Union[Paper, sch.Paper]):
def display(paper: Union[Paper, sch.Paper], excerpt=None):
"""Print the paper in long form on the terminal.

Long form includes abstract, affiliations, keywords, number of
Expand Down Expand Up @@ -119,7 +120,9 @@ def display(paper: Union[Paper, sch.Paper]):
print(f" {T.bold_green(typ)} {link}")
print_field("Citations", paper.citation_count)
if hasattr(paper, "excerpt"):
before, match, after = paper.excerpt
excerpt = paper.excerpt
if excerpt:
before, match, after = excerpt
print_field("Excerpt", before + T.bold_red(match) + after)


Expand Down Expand Up @@ -157,6 +160,13 @@ def display(venue: Venue):
print(f" {T.bold_green(typ):20} {link}")


@ovld
def display(extattr: ExtendAttr):
attrs = {**extattr.__dict__}
del attrs["_search_result"]
return display(extattr._search_result, **attrs)


def join(elems, sep=", ", lastsep=None):
"""Create a list using the given separators.

Expand Down