Skip to content

Commit

Permalink
Merge branch 'master' into ml-evs/validate_meta_schema_field
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Jul 4, 2022
2 parents 0970b13 + 4ae767b commit db6dbcc
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 0

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
ref: ${{ env.PUBLISH_UPDATE_BRANCH }}

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand All @@ -47,7 +47,7 @@ jobs:
submodules: true

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand All @@ -72,7 +72,7 @@ jobs:
submodules: true

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
fetch-depth: 2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -301,7 +301,7 @@ jobs:
with:
submodules: true

- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down Expand Up @@ -330,7 +330,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd_updated_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Set up Python 3.8
if: env.RELEASE_RUN == 'false'
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
ref: ${{ env.DEFAULT_REPO_BRANCH }}

- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ default_language_version:

repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
name: Blacken

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: check-symlinks
- id: check-yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/api_reference/models/baseinfo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# baseinfo

::: optimade.models.baseinfo
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/entries.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# entries

::: optimade.models.entries
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/index_metadb.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# index_metadb

::: optimade.models.index_metadb
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/jsonapi.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# jsonapi

::: optimade.models.jsonapi
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/links.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# links

::: optimade.models.links
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/optimade_json.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# optimade_json

::: optimade.models.optimade_json
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/references.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# references

::: optimade.models.references
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/responses.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# responses

::: optimade.models.responses
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/structures.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# structures

::: optimade.models.structures
rendering:
options:
show_if_no_docstring: true
2 changes: 1 addition & 1 deletion docs/api_reference/models/utils.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# utils

::: optimade.models.utils
rendering:
options:
show_if_no_docstring: true
2 changes: 2 additions & 0 deletions docs/api_reference/server/config.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# config

::: optimade.server.config
options:
show_if_no_docstring: true
16 changes: 8 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ plugins:
default_handler: python
handlers:
python:
rendering:
options:
show_root_heading: false
show_root_toc_entry: true
show_root_full_path: true
Expand All @@ -62,18 +62,18 @@ plugins:
show_bases: false
group_by_category: true
heading_level: 2
selection:
filters:
- "!^_[^_]"
- "!__json_encoder__$"
- "!__all__$"
- "!__config__$"
- "!ValidatorResults$"
members: true
inherited_members: false
members: null
# inherited_members: false # not yet supported
docstring_style: google
docstring_options:
replace_admonitions: true
watch:
- optimade
enable_inventory: true
- awesome-pages
- autorefs

watch:
- optimade
2 changes: 1 addition & 1 deletion optimade/adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def convert(self, format: str) -> Any:

@staticmethod
def _get_model_attributes(
starting_instances: Union[Tuple[BaseModel], List[BaseModel]], name: str
starting_instances: Union[Tuple[BaseModel, ...], List[BaseModel]], name: str
) -> Any:
"""Helper method for retrieving the OPTIMADE model's attribute, supporting "."-nested attributes"""
for res in starting_instances:
Expand Down
2 changes: 1 addition & 1 deletion optimade/adapters/structures/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _pad_iter_of_iters(
def pad_cell(
lattice_vectors: Tuple[Vector3D, Vector3D, Vector3D],
padding: Optional[float] = None,
) -> Tuple[Tuple[Vector3D, Vector3D, Vector3D], bool]:
) -> tuple: # Setting this properly makes MkDocs fail.
"""Turn any `null`/`None` values into a `float` in given `tuple` of
[`lattice_vectors`][optimade.models.structures.StructureResourceAttributes.lattice_vectors].
Expand Down
10 changes: 7 additions & 3 deletions optimade/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import re
import itertools
from enum import Enum
from typing import Optional
from typing import Optional, TYPE_CHECKING

from pydantic import Field
from pydantic.fields import FieldInfo

if TYPE_CHECKING: # pragma: no cover
from typing import Any


_PYDANTIC_FIELD_KWARGS = list(inspect.signature(Field).parameters.keys())

__all__ = (
Expand Down Expand Up @@ -55,9 +59,9 @@ def StrictPydanticField(*args, **kwargs):


def StrictField(
*args,
*args: "Any",
description: str = None,
**kwargs,
**kwargs: "Any",
) -> StrictFieldInfo:
"""A wrapper around `pydantic.Field` that does the following:
Expand Down
11 changes: 6 additions & 5 deletions optimade/server/entry_collections/entry_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def insert(self, data: List[EntryResource]) -> None:
"""

@abstractmethod
def count(self, **kwargs) -> int:
def count(self, **kwargs: Any) -> int:
"""Returns the number of entries matching the query specified
by the keyword arguments.
Parameters:
kwargs (dict): Query parameters as keyword arguments.
**kwargs: Query parameters as keyword arguments.
"""

Expand Down Expand Up @@ -160,12 +160,13 @@ def find(

bad_optimade_fields = set()
bad_provider_fields = set()
supported_prefixes = self.resource_mapper.SUPPORTED_PREFIXES
all_attributes = self.resource_mapper.ALL_ATTRIBUTES
for field in include_fields:
if field not in self.resource_mapper.ALL_ATTRIBUTES:
if field not in all_attributes:
if field.startswith("_"):
if any(
field.startswith(f"_{prefix}_")
for prefix in self.resource_mapper.SUPPORTED_PREFIXES
field.startswith(f"_{prefix}_") for prefix in supported_prefixes
):
bad_provider_fields.add(field)
else:
Expand Down
4 changes: 2 additions & 2 deletions optimade/server/entry_collections/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def __len__(self) -> int:
"""Returns the total number of entries in the collection."""
return self.collection.estimated_document_count()

def count(self, **kwargs) -> int:
def count(self, **kwargs: Any) -> int:
"""Returns the number of entries matching the query specified
by the keyword arguments.
Parameters:
kwargs (dict): Query parameters as keyword arguments. The keys
**kwargs: Query parameters as keyword arguments. The keys
'filter', 'skip', 'limit', 'hint' and 'maxTimeMS' will be passed
to the `pymongo.collection.Collection.count_documents` method.
Expand Down
2 changes: 1 addition & 1 deletion optimade/server/routers/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def render_landing_page(url: str) -> HTMLResponse:
web safe before inclusion in the template.
"""
meta = meta_values(url, 1, 1, more_data_available=False)
meta = meta_values(url, 1, 1, more_data_available=False, schema=CONFIG.schema_url)
major_version = __api_version__.split(".")[0]
versioned_url = f"{get_base_url(url)}/v{major_version}/"

Expand Down
15 changes: 12 additions & 3 deletions optimade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"""

import json
from typing import List, Iterable

from pydantic import ValidationError
from optimade.models.links import LinksResource

PROVIDER_LIST_URLS = (
Expand Down Expand Up @@ -37,7 +39,8 @@ def get_providers(add_mongo_id: bool = False) -> list:
`/links`-endpoint.
Arguments:
Whether to populate the `_id` field of the provider with MongoDB ObjectID.
add_mongo_id: Whether to populate the `_id` field of the provider with MongoDB
ObjectID.
Returns:
List of raw JSON-decoded providers including MongoDB object IDs.
Expand Down Expand Up @@ -127,15 +130,21 @@ def get_child_database_links(
links_endp = base_url + "/v1/links"
try:
links = requests.get(links_endp, timeout=10)
except requests.ConnectionError as exc:
except (requests.ConnectionError, requests.Timeout) as exc:
raise RuntimeError(f"Unable to connect to provider {provider['id']}") from exc

if links.status_code != 200:
raise RuntimeError(
f"Invalid response from {links_endp} for provider {provider['id']}: {links.content}."
)

links = LinksResponse(**links.json())
try:
links = LinksResponse(**links.json())
except (ValidationError, json.JSONDecodeError) as exc:
raise RuntimeError(
f"Did not understand response from {provider['id']}: {links.content}"
) from exc

return [
link
for link in links.data
Expand Down
2 changes: 1 addition & 1 deletion requirements-client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ aiida-core==2.0.1;python_version>='3.8'
ase==3.22.1
jarvis-tools==2022.5.20
numpy==1.21.5;python_version<'3.8'
numpy==1.22.4;python_version>='3.8'
numpy==1.23.0;python_version>='3.8'
pymatgen==2022.0.16
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ codecov==2.1.12
invoke==1.7.1
jsondiff==2.0.0
pre-commit==2.19.0
pylint==2.13.9
pylint==2.14.3
pytest==7.1.2
pytest-cov==3.0.0
pytest-httpx==0.21.0
5 changes: 3 additions & 2 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
griffe==0.21 # Currently mkdocstrings-python does not pin a griffe version, but it is quite flaky...
markupsafe==2.0.1 # Can be removed once aiida supports Jinja2>=3, see pallets/markupsafe#284
mike==1.1.2
mkdocs==1.3.0
mkdocs-awesome-pages-plugin==2.7.0
mkdocs-material==8.2.16
mkdocstrings==0.18.1
mkdocs-material==8.3.8
mkdocstrings[python]==0.19.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ mongomock==4.0.0
pydantic==1.9.1
pymongo==4.1.1
pyyaml==5.4
requests==2.27.1
requests==2.28.0
typing-extensions==4.0.0;python_version<'3.8'
uvicorn==0.17.6
uvicorn==0.18.1

0 comments on commit db6dbcc

Please sign in to comment.