Skip to content

Commit

Permalink
Final fixup
Browse files Browse the repository at this point in the history
- Tidy up changes re: `Datatype`

- Revert to using `typing.Callable` due to old Python 3.9 bug

- Move docstring note about dates back to config of Response model

- Revert class name from `Datatype` back to `DataType`

- Remove defunct comment
  • Loading branch information
ml-evs committed Oct 23, 2023
1 parent f2ad2ac commit 379110c
Show file tree
Hide file tree
Showing 15 changed files with 2,178 additions and 1,068 deletions.
849 changes: 591 additions & 258 deletions openapi/index_openapi.json

Large diffs are not rendered by default.

2,343 changes: 1,561 additions & 782 deletions openapi/openapi.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions optimade/adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
and [`StructureResource`][optimade.models.structures.StructureResource]s, respectively.
"""
import re
from collections.abc import Callable
from typing import Any, Optional, Union
from typing import Any, Callable, Optional, Union

from pydantic import BaseModel

Expand Down
2 changes: 1 addition & 1 deletion optimade/adapters/structures/adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Callable
from typing import Callable

from optimade.adapters.base import EntryAdapter
from optimade.models import StructureResource
Expand Down
6 changes: 3 additions & 3 deletions optimade/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ def _get(
"base_urls": base_url,
"use_async": use_async,
"max_results_per_provider": max_results_per_provider,
"include_providers": set(_.strip() for _ in include_providers.split(","))
"include_providers": {_.strip() for _ in include_providers.split(",")}
if include_providers
else None,
"exclude_providers": set(_.strip() for _ in exclude_providers.split(","))
"exclude_providers": {_.strip() for _ in exclude_providers.split(",")}
if exclude_providers
else None,
"exclude_databases": set(_.strip() for _ in exclude_databases.split(","))
"exclude_databases": {_.strip() for _ in exclude_databases.split(",")}
if exclude_databases
else None,
"silent": silent,
Expand Down
15 changes: 7 additions & 8 deletions optimade/models/jsonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,7 @@ class Resource(BaseResource):


class Response(BaseModel):
"""A top-level response.
The specification mandates that datetimes must be encoded following
[RFC3339](https://tools.ietf.org/html/rfc3339), which does not support
fractional seconds, thus they must be stripped in the response. This can
cause issues when the underlying database contains fields that do include
microseconds, as filters may return unexpected results.
"""
"""A top-level response."""

data: Annotated[
Optional[Union[None, Resource, list[Resource]]],
Expand Down Expand Up @@ -424,3 +417,9 @@ def either_data_meta_or_errors_must_be_set(self) -> "Response":
)
}
)
"""The specification mandates that datetimes must be encoded following
[RFC3339](https://tools.ietf.org/html/rfc3339), which does not support
fractional seconds, thus they must be stripped in the response. This can
cause issues when the underlying database contains fields that do include
microseconds, as filters may return unexpected results.
"""
8 changes: 4 additions & 4 deletions optimade/models/optimade_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from optimade.models.utils import StrictField

__all__ = (
"Datatype",
"DataType",
"ResponseMetaQuery",
"Provider",
"ImplementationMaintainer",
Expand All @@ -25,7 +25,7 @@
)


class Datatype(Enum):
class DataType(Enum):
"""Optimade Data types
See the section "Data types" in the OPTIMADE API specification for more information.
Expand All @@ -48,7 +48,7 @@ def get_values(cls) -> list[str]:
@classmethod
def from_python_type(
cls, python_type: Union[type, str, object]
) -> Optional["Datatype"]:
) -> Optional["DataType"]:
"""Get OPTIMADE data type from a Python type"""
mapping = {
"bool": cls.BOOLEAN,
Expand Down Expand Up @@ -91,7 +91,7 @@ def from_python_type(
return mapping.get(python_type, None)

@classmethod
def from_json_type(cls, json_type: str) -> Optional["Datatype"]:
def from_json_type(cls, json_type: str) -> Optional["DataType"]:
"""Get OPTIMADE data type from a named JSON type"""
mapping = {
"string": cls.STRING,
Expand Down
4 changes: 2 additions & 2 deletions optimade/models/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def null_values_for_whole_vector(
return value

for vector in value:
if None in vector and any((isinstance(_, float) for _ in vector)):
if None in vector and any(isinstance(_, float) for _ in vector):
raise ValueError(
"A lattice vector MUST be either all `null` or all numbers "
f"(vector: {vector}, all vectors: {value})"
Expand Down Expand Up @@ -1080,7 +1080,7 @@ def validate_species(
def validate_structure_features(self) -> "StructureResourceAttributes":
if [
StructureFeatures(value)
for value in sorted((_.value for _ in self.structure_features))
for value in sorted(_.value for _ in self.structure_features)
] != self.structure_features:
raise ValueError(
"structure_features MUST be sorted alphabetically, structure_features: "
Expand Down
3 changes: 2 additions & 1 deletion optimade/server/entry_collections/entry_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import re
import warnings
from abc import ABC, abstractmethod
from typing import Any, Iterable, Optional, Union
from collections.abc import Iterable
from typing import Any, Optional, Union

from lark import Transformer

Expand Down
1 change: 0 additions & 1 deletion optimade/server/routers/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def _generate_entry_info_response(entry: str) -> EntryInfoResource:
description=getattr(schema, "__doc__", "Entry Resources"),
properties=properties,
output_fields_by_format=output_fields_by_format,
# schema=CONFIG.schema_url, # I think this should be removed?
)

return EntryInfoResponse(
Expand Down
3 changes: 2 additions & 1 deletion optimade/server/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Any, Iterable, Optional
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any, Optional

from pydantic import BaseModel, TypeAdapter

Expand Down
3 changes: 1 addition & 2 deletions optimade/validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import time
import traceback as tb
import urllib.parse
from collections.abc import Callable
from typing import Any, Optional
from typing import Any, Callable, Optional

import requests
from pydantic import Field, ValidationError
Expand Down
2 changes: 1 addition & 1 deletion tests/filtertransformers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Callable

from optimade.server.mappers import BaseResourceMapper

Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _minor_deformities() -> "Generator[dict[str, Any], None, None]":
"""Generate minor deformities from correlated structure fields"""
from optimade.models.structures import CORRELATED_STRUCTURE_FIELDS

return ({f: None} for f in set(f for _ in CORRELATED_STRUCTURE_FIELDS for f in _))
return ({f: None} for f in {f for _ in CORRELATED_STRUCTURE_FIELDS for f in _})


@pytest.mark.parametrize("deformity", _minor_deformities())
Expand Down
2 changes: 1 addition & 1 deletion tests/server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from optimade.warnings import OptimadeWarning

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Callable

from requests import Response

Expand Down

0 comments on commit 379110c

Please sign in to comment.