158 lines
4.4 KiB
Python
Raw Permalink Normal View History

Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts ✨ openapi-typescript 7.6.1 🚀 ../../spec/openapi_generated.yml → src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts ✨ openapi-typescript 7.6.1 🚀 ../../spec/envd/envd.yaml → src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! ✨ 🍰 ✨ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar
2025-01-17 14:28:42 -08:00
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from ..models.node_status import NodeStatus
if TYPE_CHECKING:
from ..models.machine_info import MachineInfo
from ..models.node_metrics import NodeMetrics
2025-01-17 14:28:42 -08:00
T = TypeVar("T", bound="Node")
@_attrs_define
class Node:
"""
Attributes:
cluster_id (str): Identifier of the cluster
commit (str): Commit of the orchestrator
create_fails (int): Number of sandbox create fails
create_successes (int): Number of sandbox create successes
id (str): Identifier of the node
machine_info (MachineInfo):
metrics (NodeMetrics): Node metrics
2025-01-17 14:28:42 -08:00
sandbox_count (int): Number of sandboxes running on the node
sandbox_starting_count (int): Number of starting Sandboxes
service_instance_id (str): Service instance identifier of the node
2025-01-17 14:28:42 -08:00
status (NodeStatus): Status of the node
version (str): Version of the orchestrator
2025-01-17 14:28:42 -08:00
"""
cluster_id: str
commit: str
create_fails: int
create_successes: int
id: str
machine_info: "MachineInfo"
metrics: "NodeMetrics"
2025-01-17 14:28:42 -08:00
sandbox_count: int
sandbox_starting_count: int
service_instance_id: str
2025-01-17 14:28:42 -08:00
status: NodeStatus
version: str
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
2025-01-17 14:28:42 -08:00
def to_dict(self) -> dict[str, Any]:
cluster_id = self.cluster_id
2025-01-17 14:28:42 -08:00
commit = self.commit
create_fails = self.create_fails
create_successes = self.create_successes
id = self.id
machine_info = self.machine_info.to_dict()
metrics = self.metrics.to_dict()
2025-01-17 14:28:42 -08:00
sandbox_count = self.sandbox_count
sandbox_starting_count = self.sandbox_starting_count
service_instance_id = self.service_instance_id
2025-01-17 14:28:42 -08:00
status = self.status.value
version = self.version
field_dict: dict[str, Any] = {}
2025-01-17 14:28:42 -08:00
field_dict.update(self.additional_properties)
field_dict.update(
{
"clusterID": cluster_id,
"commit": commit,
"createFails": create_fails,
"createSuccesses": create_successes,
"id": id,
"machineInfo": machine_info,
"metrics": metrics,
2025-01-17 14:28:42 -08:00
"sandboxCount": sandbox_count,
"sandboxStartingCount": sandbox_starting_count,
"serviceInstanceID": service_instance_id,
2025-01-17 14:28:42 -08:00
"status": status,
"version": version,
2025-01-17 14:28:42 -08:00
}
)
return field_dict
@classmethod
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts ✨ openapi-typescript 7.6.1 🚀 ../../spec/openapi_generated.yml → src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts ✨ openapi-typescript 7.6.1 🚀 ../../spec/envd/envd.yaml → src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! ✨ 🍰 ✨ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.machine_info import MachineInfo
from ..models.node_metrics import NodeMetrics
2025-01-17 14:28:42 -08:00
d = dict(src_dict)
cluster_id = d.pop("clusterID")
2025-01-17 14:28:42 -08:00
commit = d.pop("commit")
create_fails = d.pop("createFails")
create_successes = d.pop("createSuccesses")
id = d.pop("id")
machine_info = MachineInfo.from_dict(d.pop("machineInfo"))
metrics = NodeMetrics.from_dict(d.pop("metrics"))
2025-01-17 14:28:42 -08:00
sandbox_count = d.pop("sandboxCount")
sandbox_starting_count = d.pop("sandboxStartingCount")
service_instance_id = d.pop("serviceInstanceID")
2025-01-17 14:28:42 -08:00
status = NodeStatus(d.pop("status"))
version = d.pop("version")
2025-01-17 14:28:42 -08:00
node = cls(
cluster_id=cluster_id,
commit=commit,
create_fails=create_fails,
create_successes=create_successes,
id=id,
machine_info=machine_info,
metrics=metrics,
2025-01-17 14:28:42 -08:00
sandbox_count=sandbox_count,
sandbox_starting_count=sandbox_starting_count,
service_instance_id=service_instance_id,
2025-01-17 14:28:42 -08:00
status=status,
version=version,
2025-01-17 14:28:42 -08:00
)
node.additional_properties = d
return node
@property
def additional_keys(self) -> list[str]:
2025-01-17 14:28:42 -08:00
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties