Skip to content

Commit

Permalink
Merge pull request #45 from release-engineering/improve
Browse files Browse the repository at this point in the history
Refactor models module
  • Loading branch information
JAVGan authored Sep 18, 2024
2 parents e417c77 + 4fc93b6 commit 11cd76b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
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

0 comments on commit 11cd76b

Please sign in to comment.