Skip to content

Commit

Permalink
Enhance documentation (#354)
Browse files Browse the repository at this point in the history
* Initial commit of enhanced documentation

* Small general description changes

* Initial detailed tag documentation

* Bump maggma version

* Set db version as prerelease

* Exclude documentation from linting

* Fix db_version test
  • Loading branch information
munrojm committed Aug 4, 2021
1 parent ee9ff6d commit 76b60cf
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@

resources.update({"user_settings": [settings_resource(consumer_settings_store)]})

# === MAPI setup
from mp_api.core.documentation import description, tags_meta

api = MAPI(resources=resources, debug=debug)
api = MAPI(
resources=resources, debug=debug, description=description, tags_meta=tags_meta
)
app = api.app
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- PORT=5001
- NUM_WORKERS=4
- MPCONTRIBS_MONGO_HOST=$MPCONTRIBS_MONGO_HOST
- DB_VERSION=2021_04_26
- DB_VERSION=2021_prerelease
volumes:
- .:/app
ports:
Expand Down
2 changes: 1 addition & 1 deletion requirements-server.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi==0.68.0
maggma==0.30.2
maggma==0.30.3
uvicorn==0.14.0
gunicorn[gevent]==20.1.0
boto3==1.18.11
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pydantic==1.8.2
pymatgen==2022.0.11
typing-extensions==3.10.0.0
maggma==0.30.2
maggma==0.30.3
requests==2.26.0
monty==2021.7.8
emmet-core==0.9.1
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ count = True
ignore = E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,W505,E741,W605,W293
max-line-length = 120
statistics = True
exclude = documentation.py

[flake8]
exclude = .git,__pycache__,docs_rst/conf.py,tests,pymatgen/io/abinit,__init__.py
exclude = .git,__pycache__,docs_rst/conf.py,tests,__init__.py,documentation.py
# max-complexity = 10
extend-ignore = E741, F401, F403
max-line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"requests>=2.23.0",
"monty",
"emmet-core",
"maggma>=0.30.2",
"maggma>=0.30.3",
"ratelimit",
],
extras_require={
Expand Down
26 changes: 22 additions & 4 deletions src/mp_api/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from maggma.api.resource.core import Resource
from pymatgen.core import __version__ as pmg_version # type: ignore
from mp_api.core.settings import MAPISettings
from mp_api import __version__ as api_version
from fastapi.openapi.utils import get_openapi
from maggma.api.API import API

Expand All @@ -15,12 +16,23 @@ def __init__(
self,
resources: Dict[str, List[Resource]],
title="Materials Project API",
version="v3.0-dev",
version=api_version,
debug=False,
heartbeat_meta={"pymatgen": pmg_version, "db_version": MAPISettings().db_version},
heartbeat_meta={
"pymatgen": pmg_version,
"db_version": MAPISettings().db_version,
},
description=None,
tags_meta=None,
):
super().__init__(
resources=resources, title=title, version=version, debug=debug, heartbeat_meta=heartbeat_meta,
resources=resources,
title=title,
version=version,
debug=debug,
heartbeat_meta=heartbeat_meta,
description=description,
tags_meta=tags_meta,
)

@property
Expand All @@ -31,7 +43,13 @@ def app(self):
app = super().app

def custom_openapi():
openapi_schema = get_openapi(title=self.title, version=self.version, routes=app.routes)
openapi_schema = get_openapi(
title=self.title,
version=self.version,
routes=app.routes,
description=self.description,
tags=self.tags_meta,
)

openapi_schema["components"]["securitySchemes"] = {
"ApiKeyAuth": {
Expand Down
258 changes: 258 additions & 0 deletions src/mp_api/core/documentation.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mp_api/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MAPISettings(BaseSettings):
description="Directory with test files",
)

db_version: str = Field("2021_04_26", description="Database version")
db_version: str = Field("2021_prerelease", description="Database version")

requests_per_min: int = Field(
60, description="Number of requests per minute to for rate limit."
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def test_get_structure_by_material_id(self, mpr):
with pytest.warns(UserWarning):
mpr.get_structure_by_material_id("mp-698856")

@pytest.mark.xfail # temp xfail until deployment
def test_get_database_version(self, mpr):
db_version = mpr.get_database_version()
assert db_version == MAPISettings().db_version

def test_get_materials_id_from_task_id(self, mpr):
assert mpr.get_materials_id_from_task_id("mp-540081") == "mp-19017"

@pytest.mark.xfail
def test_get_materials_id_references(self, mpr):
data = mpr.get_materials_id_references("mp-123")
assert len(data) > 5
Expand Down

0 comments on commit 76b60cf

Please sign in to comment.