Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* General store endpoint added * Bump pymatgen in api * Bump emmet * Add general store client to ignore test * Remove robocrys from client test * Enable mprester tests * Revert pymatgen version * Update tests * Xfail robocrys text search method
- Loading branch information
Showing
15 changed files
with
191 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pydantic==1.8.2 | ||
pymatgen==2022.0.15 | ||
pymatgen>=2022.0.16 | ||
typing-extensions==3.10.0.2 | ||
maggma==0.31.0 | ||
requests==2.26.0 | ||
monty==2021.8.17 | ||
emmet-core==0.14.6 | ||
emmet-core==0.15.0 | ||
ratelimit==2.2.1 |
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
Empty file.
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,43 @@ | ||
from typing import Dict | ||
|
||
from mp_api.core.client import BaseRester | ||
from mp_api.routes._general_store.models import GeneralStoreDoc | ||
|
||
|
||
class GeneralStoreRester(BaseRester[GeneralStoreDoc]): # pragma: no cover | ||
|
||
suffix = "_general_store" | ||
document_model = GeneralStoreDoc # type: ignore | ||
primary_key = "submission_id" | ||
monty_decode = False | ||
use_document_model = False | ||
|
||
def set_user_settings( | ||
self, kind: str, markdown: str, meta: Dict | ||
): # pragma: no cover | ||
""" | ||
Set general store data. | ||
Args: | ||
kind: Data type description | ||
markdown: Markdown data | ||
meta: Metadata | ||
Returns: | ||
Dictionary with written data and submission id. | ||
Raises: | ||
MPRestError | ||
""" | ||
return self._post_resource( | ||
body=meta, params={"kind": kind, "markdown": markdown} | ||
).get("data") | ||
|
||
def get_data(self, kind): # pragma: no cover | ||
""" | ||
Get general store data. | ||
Args: | ||
kind: Data type description | ||
Returns: | ||
List of dictionaries with kind, markdown, metadata, and submission_id. | ||
Raises: | ||
MPRestError | ||
""" | ||
return self.search(kind=kind) |
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,19 @@ | ||
from pydantic import BaseModel, Field | ||
from datetime import datetime | ||
|
||
|
||
class GeneralStoreDoc(BaseModel): | ||
""" | ||
Defines general store data | ||
""" | ||
|
||
kind: str = Field(None, description="Type of the data.") | ||
|
||
markdown: str = Field(None, description="Markdown data.") | ||
|
||
meta: str = Field(None, description="Metadata.") | ||
|
||
last_updated: datetime = Field( | ||
description="Timestamp for when this document was last updated", | ||
default_factory=datetime.utcnow, | ||
) |
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,39 @@ | ||
from typing import Dict | ||
from fastapi import Query, Body | ||
from maggma.api.utils import STORE_PARAMS | ||
from maggma.api.query_operator import QueryOperator | ||
|
||
|
||
class GeneralStorePostQuery(QueryOperator): | ||
"""Query operators to provide general store information to post""" | ||
|
||
def query( | ||
self, | ||
kind: str = Query(..., title="Data type"), | ||
markdown: str = Query(None, title="Markdown data"), | ||
meta: Dict = Body(None, title="Metadata"), | ||
) -> STORE_PARAMS: | ||
|
||
self.kind = kind | ||
self.markdown = markdown | ||
self.metadata = meta | ||
|
||
crit = {"kind": kind, "markdown": markdown, "meta": meta} | ||
|
||
return {"criteria": crit} | ||
|
||
def post_process(self, written): | ||
|
||
d = [{"kind": self.kind, "markdown": self.markdown, "meta": self.metadata}] | ||
|
||
return d | ||
|
||
|
||
class GeneralStoreGetQuery(QueryOperator): | ||
"""Query operators to obtain general store information""" | ||
|
||
def query(self, kind: str = Query(..., title="Data type")) -> STORE_PARAMS: | ||
|
||
crit = {"kind": kind} | ||
|
||
return {"criteria": crit} |
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,20 @@ | ||
from maggma.api.resource import SubmissionResource | ||
from mp_api.routes._general_store.query_operator import ( | ||
GeneralStorePostQuery, | ||
GeneralStoreGetQuery, | ||
) | ||
from mp_api.routes._general_store.models import GeneralStoreDoc | ||
|
||
|
||
def general_store_resource(general_store): | ||
resource = SubmissionResource( | ||
general_store, | ||
GeneralStoreDoc, | ||
post_query_operators=[GeneralStorePostQuery()], | ||
get_query_operators=[GeneralStoreGetQuery()], | ||
enable_default_search=True, | ||
include_in_schema=True, | ||
calculate_submission_id=True, | ||
) | ||
|
||
return resource |
Empty file.
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,48 @@ | ||
from mp_api.routes._general_store.query_operator import ( | ||
GeneralStoreGetQuery, | ||
GeneralStorePostQuery, | ||
) | ||
|
||
from monty.tempfile import ScratchDir | ||
from monty.serialization import loadfn, dumpfn | ||
|
||
|
||
def test_user_settings_post_query(): | ||
op = GeneralStorePostQuery() | ||
|
||
assert op.query( | ||
kind="test", meta={"test": "test", "test2": 10}, markdown="test" | ||
) == { | ||
"criteria": { | ||
"kind": "test", | ||
"meta": {"test": "test", "test2": 10}, | ||
"markdown": "test", | ||
} | ||
} | ||
|
||
with ScratchDir("."): | ||
dumpfn(op, "temp.json") | ||
new_op = loadfn("temp.json") | ||
assert new_op.query( | ||
kind="test", meta={"test": "test", "test2": 10}, markdown="test" | ||
) == { | ||
"criteria": { | ||
"kind": "test", | ||
"meta": {"test": "test", "test2": 10}, | ||
"markdown": "test", | ||
} | ||
} | ||
|
||
docs = [{"kind": "test", "meta": {"test": "test", "test2": 10}, "markdown": "test"}] | ||
assert op.post_process(docs) == docs | ||
|
||
|
||
def test_user_settings_get_query(): | ||
op = GeneralStoreGetQuery() | ||
|
||
assert op.query(kind="test") == {"criteria": {"kind": "test"}} | ||
|
||
with ScratchDir("."): | ||
dumpfn(op, "temp.json") | ||
new_op = loadfn("temp.json") | ||
assert new_op.query(kind="test") == {"criteria": {"kind": "test"}} |
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
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