Skip to content

Commit

Permalink
Fix ovld display / export exception with ExtendAttr class
Browse files Browse the repository at this point in the history
  • Loading branch information
satyaog committed Oct 27, 2023
1 parent b73cf3c commit 15cf86b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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
9 changes: 8 additions & 1 deletion paperoni/db/model_export.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ovld import ovld

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


@ovld
def export(paper: sch.Paper):
return M.Paper(
Expand Down Expand Up @@ -86,3 +86,10 @@ def export(venue: sch.Venue):
volume=venue.volume,
quality=venue.quality,
)


@ovld
def export(extattr: ExtendAttr):
attrs = {**extattr.__dict__}
del attrs["_search_result"]
export(extattr._search_result, **attrs)
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"]
display(extattr._search_result, **attrs)


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

0 comments on commit 15cf86b

Please sign in to comment.