|
4 | 4 | from pathlib import PurePosixPath |
5 | 5 | from typing import Any, Dict, List, Optional, Union |
6 | 6 |
|
| 7 | +import orjson |
7 | 8 | from pydantic import Field, ValidationError, conint, constr, root_validator, validator |
8 | 9 | from typing_extensions import Annotated, Literal |
9 | 10 |
|
|
18 | 19 | from dstack._internal.core.models.services import AnyModel, OpenAIChatModel |
19 | 20 | from dstack._internal.core.models.unix import UnixUser |
20 | 21 | from dstack._internal.core.models.volumes import MountPoint, VolumeConfiguration, parse_mount_point |
| 22 | +from dstack._internal.utils.json_utils import get_orjson_default_options, orjson_default |
21 | 23 |
|
22 | 24 | CommandsList = List[str] |
23 | 25 | ValidPort = conint(gt=0, le=65536) |
@@ -566,13 +568,25 @@ def parse_apply_configuration(data: dict) -> AnyApplyConfiguration: |
566 | 568 | AnyDstackConfiguration = AnyApplyConfiguration |
567 | 569 |
|
568 | 570 |
|
| 571 | +# Custom _orjson_dumps for DstackConfiguration with indentation |
| 572 | +def _orjson_dumps(v: Any, *, default: Any) -> str: |
| 573 | + return orjson.dumps( |
| 574 | + v, |
| 575 | + option=get_orjson_default_options() | orjson.OPT_INDENT_2, |
| 576 | + default=orjson_default, |
| 577 | + ).decode() |
| 578 | + |
| 579 | + |
569 | 580 | class DstackConfiguration(CoreModel): |
570 | 581 | __root__: Annotated[ |
571 | 582 | AnyDstackConfiguration, |
572 | 583 | Field(discriminator="type"), |
573 | 584 | ] |
574 | 585 |
|
575 | 586 | class Config: |
| 587 | + json_loads = orjson.loads |
| 588 | + json_dumps = _orjson_dumps |
| 589 | + |
576 | 590 | @staticmethod |
577 | 591 | def schema_extra(schema: Dict[str, Any]): |
578 | 592 | schema["$schema"] = "http://json-schema.org/draft-07/schema#" |
|
0 commit comments