Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Mar 17, 2023
1 parent 04506c4 commit c3cfa80
Show file tree
Hide file tree
Showing 15 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion fatcat_scholar/djvu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def djvu_extract_leaf_texts(
if only_leaves:
max_leaf = max(only_leaves)
elem_iter = ET.iterparse(blob, ["start", "end"])
for (event, element) in elem_iter:
for event, element in elem_iter:
if event == "start":
continue
if not (element.tag == "OBJECT" and event == "end"):
Expand Down
2 changes: 1 addition & 1 deletion fatcat_scholar/issue_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def load_counts(self, es_client: Any) -> None:
)
cur: Any = self.db.cursor()
count = 0
for (sim_pubid, container_ident) in all_pub_containers:
for sim_pubid, container_ident in all_pub_containers:
count += 1
if count % 500 == 0:
print(f" {count}...", file=sys.stderr)
Expand Down
2 changes: 0 additions & 2 deletions fatcat_scholar/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def create_kafka_consumer(
"""

def _on_rebalance(consumer: Any, partitions: Any) -> None:

for p in partitions:
if p.error:
raise KafkaException(p.error)
Expand Down Expand Up @@ -160,7 +159,6 @@ def create_kafka_producer(kafka_brokers: List[str]) -> Producer:
return Producer(config)

def run(self) -> Counter:

if self.batch_timeout_sec:
signal.signal(signal.SIGALRM, self._timeout_handler)

Expand Down
4 changes: 0 additions & 4 deletions fatcat_scholar/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ def contrib_affiliation(contrib: ReleaseContrib) -> Optional[str]:


def es_abstracts_from_grobid(tei_doc: GrobidDocument) -> List[ScholarAbstract]:

if tei_doc.abstract:
body = scrub_text(tei_doc.abstract)
if body:
Expand All @@ -505,7 +504,6 @@ def es_abstracts_from_grobid(tei_doc: GrobidDocument) -> List[ScholarAbstract]:


def es_abstracts_from_release(release: ReleaseEntity) -> List[ScholarAbstract]:

d = dict()
for abst in release.abstracts:
if abst.lang not in d:
Expand All @@ -518,7 +516,6 @@ def es_abstracts_from_release(release: ReleaseEntity) -> List[ScholarAbstract]:


def es_biblio_from_release(release: ReleaseEntity) -> ScholarBiblio:

container_name = release.extra and release.extra.get("container_name")
container_sherpa_color = None

Expand Down Expand Up @@ -622,7 +619,6 @@ def es_biblio_from_release(release: ReleaseEntity) -> ScholarBiblio:


def es_release_from_release(release: ReleaseEntity) -> ScholarRelease:

if release.container:
container_name = release.container.name
container_ident = release.container.redirect or release.container.ident
Expand Down
2 changes: 0 additions & 2 deletions fatcat_scholar/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def apply_filters(search: Search, query: FulltextQuery) -> Search:


def process_query(query: FulltextQuery) -> FulltextHits:

if not query.q:
return do_fulltext_search(query)

Expand Down Expand Up @@ -295,7 +294,6 @@ def do_lookup_query(lookup: str) -> FulltextHits:
def do_fulltext_search(
query: FulltextQuery, deep_page_limit: int = 2000
) -> FulltextHits:

search = Search(using=es_client, index=settings.ELASTICSEARCH_QUERY_FULLTEXT_INDEX)

if query.collapse_key:
Expand Down
5 changes: 0 additions & 5 deletions fatcat_scholar/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def es_sim_from_sim(sim: Dict[str, Any]) -> ScholarSim:


def es_biblio_from_sim(sim: Dict[str, Any]) -> ScholarBiblio:

issue_meta = sim["issue_item_metadata"]["metadata"]
pub_meta = sim["pub_item_metadata"]["metadata"]

Expand Down Expand Up @@ -264,7 +263,6 @@ def es_fulltext_from_grobid(
def es_fulltext_from_pdftotext(
raw_text: str, pdf_meta: Optional[dict], re: ReleaseEntity, fe: FileEntity
) -> Optional[ScholarFulltext]:

if raw_text and len(raw_text) > MAX_BODY_CHARS:
raw_text = raw_text[:MAX_BODY_CHARS]
ret = ScholarFulltext(
Expand All @@ -281,7 +279,6 @@ def es_fulltext_from_html(
re: ReleaseEntity,
wc: WebcaptureEntity,
) -> Optional[ScholarFulltext]:

if not wc.archive_urls or not html_fulltext.get("tei_xml"):
return None

Expand Down Expand Up @@ -407,7 +404,6 @@ def biblio_metadata_hacks(biblio: ScholarBiblio) -> ScholarBiblio: # noqa: C901
def generate_tags(
biblio: ScholarBiblio, primary_release: Optional[ReleaseEntity]
) -> List[str]:

tags = []

# tags
Expand Down Expand Up @@ -466,7 +462,6 @@ def check_exclude_web(biblio: ScholarBiblio) -> bool:


def transform_heavy(heavy: IntermediateBundle) -> Optional[ScholarDoc]:

tags: List[str] = []
work_ident: Optional[str] = None
sim_issue: Optional[str] = None
Expand Down
3 changes: 0 additions & 3 deletions fatcat_scholar/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def web_search(
lang: LangPrefix = Depends(LangPrefix),
content: ContentNegotiation = Depends(ContentNegotiation),
) -> Any:

if content.mimetype == "application/json":
return search(query)
hits: Optional[FulltextHits] = None
Expand Down Expand Up @@ -250,7 +249,6 @@ def web_feed_rss(
query: FulltextQuery = Depends(FulltextQuery),
lang: LangPrefix = Depends(LangPrefix),
) -> fastapi_rss.RSSResponse:

# override some query params for feeds
original_query = query.q
if query.q:
Expand Down Expand Up @@ -314,7 +312,6 @@ def web_work(
lang: LangPrefix = Depends(LangPrefix),
content: ContentNegotiation = Depends(ContentNegotiation),
) -> Any:

if content.mimetype == "application/json":
return get_work(work_ident)

Expand Down
1 change: 0 additions & 1 deletion fatcat_scholar/work_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def fetch_webcapture_html_fulltext(
wc: WebcaptureEntity,
release_ident: str,
) -> Optional[Dict[str, Any]]:

primary_resources = [cdx for cdx in wc.cdx if cdx.url == wc.original_url]
if not primary_resources or primary_resources[0].mimetype != "text/html":
return None
Expand Down
1 change: 0 additions & 1 deletion fatcat_scholar/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def __init__(self, es_client: Any, es_index: str, **kwargs: Any):
self.es_index = es_index

def process_batch(self, batch: List[dict]) -> None:

bulk_actions = []
for obj in batch:
bundle = IntermediateBundle.from_json(obj)
Expand Down
1 change: 0 additions & 1 deletion tests/test_djvu_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def test_djvu_extract_leaf_texts() -> None:

# https://archive.org/details/ERIC_ED441501
with open("tests/files/ERIC_ED441501_djvu.xml", "r") as f:
blob = f.read()
Expand Down
1 change: 0 additions & 1 deletion tests/test_issue_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def test_issue_db_basics() -> None:

api_conf = fatcat_openapi_client.Configuration()
api_conf.host = settings.FATCAT_API_HOST
api = fatcat_openapi_client.DefaultApi(fatcat_openapi_client.ApiClient(api_conf))
Expand Down
2 changes: 0 additions & 2 deletions tests/test_refs_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


def test_transform_refs_grobid() -> None:

with open("tests/files/example_grobid.tei.xml", "r") as f:
blob = f.read()

Expand Down Expand Up @@ -45,7 +44,6 @@ def test_transform_refs_grobid() -> None:


def test_transform_refs_crossref() -> None:

with open("tests/files/example_crossref_record.json", "r") as f:
record = json.loads(f.read())

Expand Down
4 changes: 0 additions & 4 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


def test_es_release_from_release() -> None:

with open("tests/files/release_hsmo6p4smrganpb3fndaj2lon4.json", "r") as f:
release = entity_from_json(f.read(), ReleaseEntity)

Expand All @@ -27,7 +26,6 @@ def test_es_release_from_release() -> None:


def test_es_biblio_from_release() -> None:

with open("tests/files/release_hsmo6p4smrganpb3fndaj2lon4.json", "r") as f:
release = entity_from_json(f.read(), ReleaseEntity)

Expand All @@ -43,13 +41,11 @@ def test_es_biblio_from_release() -> None:


def test_run_refs() -> None:

with open("tests/files/work_iarm6swodra2bcrzhxrfaah7py_bundle.json", "r") as f:
run_refs(f.readlines())


def test_run_transform() -> None:

with open("tests/files/work_iarm6swodra2bcrzhxrfaah7py_bundle.json", "r") as f:
run_transform(f.readlines())

Expand Down
7 changes: 1 addition & 6 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_basic_routes(client: Any) -> None:


def test_basic_search(client: Any, mocker: Any) -> None:

rv = client.get("/search")
assert rv.status_code == 200

Expand All @@ -105,7 +104,6 @@ def test_basic_search(client: Any, mocker: Any) -> None:


def test_basic_rss_feed(client: Any, mocker: Any) -> None:

with open("tests/files/elastic_fulltext_search.json") as f:
elastic_resp = json.loads(f.read())

Expand All @@ -127,7 +125,6 @@ def test_basic_rss_feed(client: Any, mocker: Any) -> None:


def test_basic_work_landing_page(client: Any, mocker: Any) -> None:

with open("tests/files/elastic_fulltext_get.json") as f:
elastic_resp = json.loads(f.read())

Expand All @@ -149,7 +146,6 @@ def test_basic_work_landing_page(client: Any, mocker: Any) -> None:


def test_basic_access_redirect(client: Any, mocker: Any) -> None:

with open("tests/files/elastic_fulltext_get.json") as f:
elastic_resp = json.loads(f.read())

Expand Down Expand Up @@ -184,7 +180,6 @@ def test_basic_access_redirect(client: Any, mocker: Any) -> None:


def test_access_redirect_fallback(client: Any, mocker: Any) -> None:

with open("tests/files/elastic_fulltext_get.json") as f:
elastic_resp = json.loads(f.read())

Expand Down Expand Up @@ -280,9 +275,9 @@ def test_access_redirect_fallback(client: Any, mocker: Any) -> None:
assert b"Access Location Not Found" in rv.content
assert b"archive.org/download/some/thing.else.pdf" in rv.content


@pytest.mark.skip(reason="todo: requires a mocked fatcat API client, not just es")
def test_access_redirect_encoding(client: Any, mocker: Any) -> None:

with open("tests/files/elastic_get_work_a6gvpil4brdgzhqyaog3ftngqe.json") as f:
elastic_ia_resp = json.loads(f.read())
with open("tests/files/elastic_get_work_ao5l3ykgbvg2vfpqe2y5qold5y.json") as f:
Expand Down
1 change: 0 additions & 1 deletion tests/test_work_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@responses.activate
def test_run_transform(mocker: Any) -> None:

issue_db = IssueDB(settings.SCHOLAR_ISSUEDB_PATH)
issue_db.init_db()

Expand Down

0 comments on commit c3cfa80

Please sign in to comment.