Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor models module #45

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
- name: Run Tox
Expand Down
67 changes: 36 additions & 31 deletions starmap_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
]


class PaginationMetadata(TypedDict):
"""Datastructure of the metadata about the paginated query."""

first: str
last: str
next: Optional[str]
page: int
per_page: int
previous: Optional[str]
total: int
total_pages: int


class PaginatedRawData(TypedDict):
"""Represent a paginated StArMap data in its raw format (Dict)."""

items: List[Any]
nav: PaginationMetadata


class Workflow(str, Enum):
"""Define the valid workflows for StArMap."""

Expand Down Expand Up @@ -85,14 +105,8 @@ def from_json(cls, json: Any):


@frozen
class StarmapBaseData:
"""Represent the common data present in StArMap entities."""

id: Optional[str] = field(validator=optional(instance_of(str)))
"""
The unique ID for a StArMap model.
This field is never set on :class:`~starmap_client.models.QueryResponse`.
"""
class MetaMixin:
"""Mixin for defining the meta attribute and its validator."""

meta: Optional[Dict[str, Any]] = field()
"""Dictionary with additional information related to a VM image."""
Expand All @@ -109,7 +123,18 @@ def _is_meta_dict_of_str_any(self, attribute: Attribute, value: Any):


@frozen
class Destination(StarmapBaseData, StarmapJSONDecodeMixin):
class StarmapBaseData(MetaMixin, StarmapJSONDecodeMixin):
"""Represent the common data present in StArMap entities."""

id: Optional[str] = field(validator=optional(instance_of(str)))
"""
The unique ID for a StArMap model.
This field is never set on :class:`~starmap_client.models.QueryResponse`.
"""


@frozen
class Destination(StarmapBaseData):
"""Represent a destination entry from Mapping."""

architecture: Optional[str] = field(validator=optional(instance_of(str)))
Expand Down Expand Up @@ -146,7 +171,7 @@ class Destination(StarmapBaseData, StarmapJSONDecodeMixin):


@frozen
class Mapping(StarmapBaseData, StarmapJSONDecodeMixin):
class Mapping(StarmapBaseData):
"""Represent a marketplace Mapping from Policy."""

destinations: List[Destination] = field(
Expand Down Expand Up @@ -176,7 +201,7 @@ class Mapping(StarmapBaseData, StarmapJSONDecodeMixin):


@frozen
class Policy(StarmapBaseData, StarmapJSONDecodeMixin):
class Policy(StarmapBaseData):
"""Represent a StArMap policy."""

mappings: List[Mapping] = field(
Expand Down Expand Up @@ -237,23 +262,3 @@ def _preprocess_json(cls, json: Any) -> Dict[str, Any]:
mappings[c] = dst
json["clouds"] = mappings
return json


class PaginationMetadata(TypedDict):
"""Datastructure of the metadata about the paginated query."""

first: str
last: str
next: Optional[str]
page: int
per_page: int
previous: Optional[str]
total: int
total_pages: int


class PaginatedRawData(TypedDict):
"""Represent a paginated StArMap data in its raw format (Dict)."""

items: List[Any]
nav: PaginationMetadata
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ commands =
pip-compile -U --generate-hashes --reuse-hashes --output-file=requirements-test.txt setup.py requirements-test.in

[testenv:docs]
basepython = python3.9
use_develop=true
commands=
sphinx-build -M html docs docs/_build
Expand Down