-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
David/use dependency injection (#174)
* restructure Catprez Endpoints add annotation listings to root endpoint / * blacked code * Test passes locally - xfail pending change to pyoxigraph testing * Black code Specify namespace to avoid race condition Add print to identify why GH action failing but local passing Add further ref data (SKOS + SDO HTTPS version) update GH actions; add init.py for tests add oxrdflib depedency QuerySender -> Repo Use Fastapi's dependency injection to allow switchable backends Add caching specifically to link generation * rename query_sender (+ variants) -> repo * remove commented code reformat with black * restructure Catprez Endpoints add annotation listings to root endpoint / * blacked code * Black code Specify namespace to avoid race condition Add print to identify why GH action failing but local passing Add further ref data (SKOS + SDO HTTPS version) update GH actions; add init.py for tests add oxrdflib depedency QuerySender -> Repo Use Fastapi's dependency injection to allow switchable backends Add caching specifically to link generation * rename query_sender (+ variants) -> repo * remove commented code reformat with black
- Loading branch information
1 parent
91ede3c
commit e1566f8
Showing
97 changed files
with
19,207 additions
and
2,853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pathlib import Path | ||
|
||
import httpx | ||
from fastapi import Depends | ||
from pyoxigraph import Store | ||
|
||
from prez.cache import store, oxrdflib_store | ||
from prez.config import settings | ||
from prez.sparql.methods import PyoxigraphRepo, RemoteSparqlRepo, OxrdflibRepo | ||
|
||
|
||
async def get_async_http_client(): | ||
return httpx.AsyncClient( | ||
auth=(settings.sparql_username, settings.sparql_password) | ||
if settings.sparql_username | ||
else None, | ||
timeout=settings.sparql_timeout, | ||
) | ||
|
||
|
||
def get_pyoxi_store(): | ||
return store | ||
|
||
|
||
def get_oxrdflib_store(): | ||
return oxrdflib_store | ||
|
||
|
||
async def get_repo( | ||
http_async_client: httpx.AsyncClient = Depends(get_async_http_client), | ||
pyoxi_store: Store = Depends(get_pyoxi_store), | ||
): | ||
if settings.sparql_repo_type == "pyoxigraph": | ||
return PyoxigraphRepo(pyoxi_store) | ||
elif settings.sparql_repo_type == "oxrdflib": | ||
return OxrdflibRepo(oxrdflib_store) | ||
elif settings.sparql_repo_type == "remote": | ||
return RemoteSparqlRepo(http_async_client) | ||
|
||
|
||
async def load_local_data_to_oxigraph(store: Store): | ||
""" | ||
Loads all the data from the local data directory into the local SPARQL endpoint | ||
""" | ||
for file in (Path(__file__).parent.parent / "rdf").glob("*.ttl"): | ||
store.load(file.read_bytes(), "text/turtle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.