Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
uhbrar committed Jan 30, 2024
1 parent 6a55702 commit 4b9297d
Show file tree
Hide file tree
Showing 28 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions strider/caching.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Caching/locking."""

import asyncio
from collections import OrderedDict, namedtuple
from functools import wraps
Expand Down
1 change: 1 addition & 0 deletions strider/constraints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constraint handling."""

import operator
import re
from reasoner_pydantic import KnowledgeGraph, HashableSequence
Expand Down
1 change: 1 addition & 0 deletions strider/fetcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fetcher 2.0."""

from collections import defaultdict
from collections.abc import Iterable
import copy
Expand Down
1 change: 1 addition & 0 deletions strider/graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Graph - a dict with extra methods."""

import json


Expand Down
2 changes: 1 addition & 1 deletion strider/knowledge_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def processor(response, last_hop: bool):
self.normalizer.curie_map,
self.logger,
self.information_content_threshold,
last_hop
last_hop,
)

return processor
Expand Down
1 change: 1 addition & 0 deletions strider/node_sets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Node sets."""

from collections import defaultdict
from datetime import datetime
from reasoner_pydantic import Message
Expand Down
1 change: 1 addition & 0 deletions strider/normalizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Node Normalizer Utilities."""

from collections import namedtuple
import logging

Expand Down
1 change: 1 addition & 0 deletions strider/openapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TRAPI FastAPI wrapper."""

from typing import Any, Dict, List, Optional

from fastapi import FastAPI
Expand Down
1 change: 1 addition & 0 deletions strider/query_planner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Query planner."""

from collections import defaultdict, namedtuple
import copy
from itertools import chain
Expand Down
1 change: 1 addition & 0 deletions strider/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
oo .d8P 888 . 888 888 888 888 888 .o 888
8""88888P' "888" d888b o888o `Y8bod88P" `Y8bod8P' d888b
"""

import copy
import datetime
import json
Expand Down
9 changes: 4 additions & 5 deletions strider/throttle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Strider TRAPI Throttle."""

import asyncio
from asyncio.queues import QueueEmpty
from asyncio.tasks import Task
Expand Down Expand Up @@ -278,11 +279,9 @@ async def process_batch(
response_values[request_id] = ReasonerResponse(
message=Message()
)
response_values[
request_id
].message.query_graph = request_value_mapping[
request_id
].message.query_graph.copy()
response_values[request_id].message.query_graph = (
request_value_mapping[request_id].message.query_graph.copy()
)
response_values[request_id].message.knowledge_graph = (
message.knowledge_graph
or KnowledgeGraph(nodes={}, edges={})
Expand Down
1 change: 1 addition & 0 deletions strider/throttle_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Throttle Utility Functions."""

from collections import defaultdict
from reasoner_pydantic import Message, QueryGraph, AuxiliaryGraphs
from reasoner_pydantic.kgraph import KnowledgeGraph
Expand Down
36 changes: 16 additions & 20 deletions strider/trapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TRAPI utilities."""

from itertools import product
import json
import logging
Expand Down Expand Up @@ -228,7 +229,7 @@ def filter_message(
curie_map: dict,
logger: logging.Logger = logging.getLogger(),
information_content_threshold: int = settings.information_content_threshold,
last_hop: bool = False
last_hop: bool = False,
) -> None:
"""Filter all nodes based on information content."""
pinned_nodes = get_curies(message.query_graph)
Expand Down Expand Up @@ -265,14 +266,9 @@ def filter_message(
or (
# Nodes that appear in the blocklist shouldn't be shown
curie is not None
and any(
n in curie.identifiers for n in blocklist
)
)
or (
curie is None
and node_binding.id in blocklist
and any(n in curie.identifiers for n in blocklist)
)
or (curie is None and node_binding.id in blocklist)
):
keep = False
if node_binding.id in message.knowledge_graph.nodes:
Expand All @@ -290,15 +286,15 @@ def filter_message(
support_graph_id
]
for edge_id in message.auxiliary_graphs[support_graph_id].edges:
kept_knowledge_graph.edges[
edge_id
] = message.knowledge_graph.edges[edge_id]
kept_knowledge_graph.edges[edge_id] = (
message.knowledge_graph.edges[edge_id]
)
# add edges from result
for edge_bindings in analysis.edge_bindings.values():
for edge_binding in edge_bindings:
kept_knowledge_graph.edges[
edge_binding.id
] = message.knowledge_graph.edges[edge_binding.id]
kept_knowledge_graph.edges[edge_binding.id] = (
message.knowledge_graph.edges[edge_binding.id]
)
# add support graphs from edge
for attribute in (
kept_knowledge_graph.edges[edge_binding.id].attributes
Expand All @@ -309,15 +305,15 @@ def filter_message(
== "biolink:support_graphs"
):
for aux_graph_id in attribute.value:
kept_aux_graphs[
aux_graph_id
] = message.auxiliary_graphs[aux_graph_id]
kept_aux_graphs[aux_graph_id] = (
message.auxiliary_graphs[aux_graph_id]
)
for edge_id in message.auxiliary_graphs[
aux_graph_id
].edges:
kept_knowledge_graph.edges[
edge_id
] = message.knowledge_graph.edges[edge_id]
kept_knowledge_graph.edges[edge_id] = (
message.knowledge_graph.edges[edge_id]
)
# keep any results that don't have promiscuous nodes
# only add result if all the knowledge and aux graph stuff worked out
kept_results.append(result)
Expand Down
1 change: 1 addition & 0 deletions strider/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""General utilities."""

import copy
import json
from json.decoder import JSONDecodeError
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test utilities."""

import asyncio
from contextlib import asynccontextmanager, AsyncExitStack
from functools import partial, wraps
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logging setup."""

import logging


Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/mock_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"categories": [
"biolink:SmallMolecule",
],
}
},
},
"edges": {
"e0": {
Expand Down Expand Up @@ -676,7 +676,7 @@
},
}
],
}
},
],
},
}
1 change: 1 addition & 0 deletions tests/helpers/normalizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""LOTR node normalizer."""

import csv
from typing import List

Expand Down
1 change: 1 addition & 0 deletions tests/helpers/redisMock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mock Redis."""

import fakeredis.aioredis as fakeredis
import gzip
import json
Expand Down
1 change: 1 addition & 0 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test constraints."""

from reasoner_pydantic import Message, AttributeConstraint, Node
from strider.constraints import satisfies_attribute_constraint, enforce_constraints

Expand Down
1 change: 1 addition & 0 deletions tests/test_kp_responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test weird kp responses."""

import httpx
import json
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_lookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Strider."""

import json

from fastapi.responses import Response
Expand Down
1 change: 1 addition & 0 deletions tests/test_node_sets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test node set handling."""

import logging

from reasoner_pydantic import (
Expand Down
8 changes: 7 additions & 1 deletion tests/test_postproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from tests.helpers.context import (
with_norm_overlay,
)
from tests.helpers.mock_responses import kp_response, response_with_aux_graphs, blocked_response
from tests.helpers.mock_responses import (
kp_response,
response_with_aux_graphs,
blocked_response,
)

from strider.config import settings

Expand Down Expand Up @@ -95,6 +99,7 @@ async def test_aux_graph_filtering():
assert len(list(msg.message.auxiliary_graphs.keys())) == 0
assert len(msg.message.results) == 1


@pytest.mark.asyncio
@pytest.mark.asyncio
@with_norm_overlay(
Expand Down Expand Up @@ -128,6 +133,7 @@ async def test_blocklist():
assert "MESH:D014867" not in msg.message.knowledge_graph.nodes
assert len(msg.message.results) == 0


@pytest.mark.asyncio
@with_norm_overlay(
settings.normalizer_url,
Expand Down
1 change: 1 addition & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Strider."""

import asyncio
import json
import redis.asyncio
Expand Down
1 change: 1 addition & 0 deletions tests/test_throttle_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Strider TRAPI Throttle LRU Caching."""

import json
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_traversal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test traversal."""

import pytest

from strider.traversal import NoAnswersError, get_traversals
Expand Down
1 change: 1 addition & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test utilities."""

from strider.utils import remove_null_values
from strider.trapi import filter_ancestor_types

Expand Down

0 comments on commit 4b9297d

Please sign in to comment.