Skip to content

Commit cc8c272

Browse files
committed
Fix generate-json-schema CI
1 parent 820b4f7 commit cc8c272

6 files changed

Lines changed: 33 additions & 25 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ jobs:
237237
run: uv sync
238238
- name: Generate json schema
239239
run: |
240-
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json(indent=2))" > configuration.json
241-
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json(indent=2))" > profiles.json
240+
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json())" > configuration.json
241+
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json())" > profiles.json
242242
- name: Upload json schema to S3
243243
run: |
244244
VERSION=$((${{ github.run_number }} + ${{ env.BUILD_INCREMENT }}))

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ jobs:
311311
run: uv sync
312312
- name: Generate json schema
313313
run: |
314-
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json(indent=2))" > configuration.json
315-
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json(indent=2))" > profiles.json
314+
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json())" > configuration.json
315+
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json())" > profiles.json
316316
- name: Upload json schema to S3
317317
run: |
318318
VERSION=${GITHUB_REF#refs/tags/}

src/dstack/_internal/core/models/common.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic_duality import DualBaseModel
99
from typing_extensions import Annotated
1010

11-
from dstack._internal.utils.json_utils import get_orjson_default_options, orjson_default
11+
from dstack._internal.utils.json_utils import pydantic_orjson_dumps
1212

1313
IncludeExcludeFieldType = Union[int, str]
1414
IncludeExcludeSetType = set[IncludeExcludeFieldType]
@@ -18,14 +18,6 @@
1818
IncludeExcludeType = Union[IncludeExcludeSetType, IncludeExcludeDictType]
1919

2020

21-
def _orjson_dumps(v: Any, *, default: Any) -> str:
22-
return orjson.dumps(
23-
v,
24-
option=get_orjson_default_options(),
25-
default=orjson_default,
26-
).decode()
27-
28-
2921
# DualBaseModel creates two classes for the model:
3022
# one with extra = "forbid" (CoreModel/CoreModel.__request__),
3123
# and another with extra = "ignore" (CoreModel.__response__).
@@ -34,7 +26,7 @@ def _orjson_dumps(v: Any, *, default: Any) -> str:
3426
class CoreModel(DualBaseModel):
3527
class Config:
3628
json_loads = orjson.loads
37-
json_dumps = _orjson_dumps
29+
json_dumps = pydantic_orjson_dumps
3830

3931
def json(
4032
self,

src/dstack/_internal/core/models/configurations.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from dstack._internal.core.models.services import AnyModel, OpenAIChatModel
2020
from dstack._internal.core.models.unix import UnixUser
2121
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
22+
from dstack._internal.utils.json_utils import (
23+
pydantic_orjson_dumps_with_indent,
24+
)
2325

2426
CommandsList = List[str]
2527
ValidPort = conint(gt=0, le=65536)
@@ -568,15 +570,6 @@ def parse_apply_configuration(data: dict) -> AnyApplyConfiguration:
568570
AnyDstackConfiguration = AnyApplyConfiguration
569571

570572

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-
580573
class DstackConfiguration(CoreModel):
581574
__root__: Annotated[
582575
AnyDstackConfiguration,
@@ -585,7 +578,7 @@ class DstackConfiguration(CoreModel):
585578

586579
class Config:
587580
json_loads = orjson.loads
588-
json_dumps = _orjson_dumps
581+
json_dumps = pydantic_orjson_dumps_with_indent
589582

590583
@staticmethod
591584
def schema_extra(schema: Dict[str, Any]):

src/dstack/_internal/core/models/profiles.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from enum import Enum
22
from typing import Any, Dict, List, Optional, Union, overload
33

4+
import orjson
45
from pydantic import Field, root_validator, validator
56
from typing_extensions import Annotated, Literal
67

78
from dstack._internal.core.models.backends.base import BackendType
89
from dstack._internal.core.models.common import CoreModel, Duration
910
from dstack._internal.utils.common import list_enum_values_for_annotation
11+
from dstack._internal.utils.json_utils import pydantic_orjson_dumps_with_indent
1012
from dstack._internal.utils.tags import tags_validator
1113

1214
DEFAULT_RETRY_DURATION = 3600
@@ -343,6 +345,9 @@ class ProfilesConfig(CoreModel):
343345
profiles: List[Profile]
344346

345347
class Config:
348+
json_loads = orjson.loads
349+
json_dumps = pydantic_orjson_dumps_with_indent
350+
346351
schema_extra = {"$schema": "http://json-schema.org/draft-07/schema#"}
347352

348353
def default(self) -> Optional[Profile]:

src/dstack/_internal/utils/json_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
import orjson
24
from pydantic import BaseModel
35

@@ -15,6 +17,22 @@
1517
ASYNCPG = False
1618

1719

20+
def pydantic_orjson_dumps(v: Any, *, default: Any) -> str:
21+
return orjson.dumps(
22+
v,
23+
option=get_orjson_default_options(),
24+
default=orjson_default,
25+
).decode()
26+
27+
28+
def pydantic_orjson_dumps_with_indent(v: Any, *, default: Any) -> str:
29+
return orjson.dumps(
30+
v,
31+
option=get_orjson_default_options() | orjson.OPT_INDENT_2,
32+
default=orjson_default,
33+
).decode()
34+
35+
1836
def orjson_default(obj):
1937
if isinstance(obj, float):
2038
# orjson does not convert float subclasses be default

0 commit comments

Comments
 (0)