Skip to content

Commit f9036f5

Browse files
committed
Restructure rest_plugin modules
1 parent e757a77 commit f9036f5

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

examples/plugins/example_plugin_server/app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import FastAPI
44

55
from app.utils import configure_logging
6-
from dstack.plugins.builtin.models import (
6+
from dstack.plugins.builtin.rest_plugin import (
77
FleetSpecRequest,
88
FleetSpecResponse,
99
GatewaySpecRequest,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ruff: noqa: F401
2+
from dstack.plugins.builtin.rest_plugin._models import (
3+
FleetSpecRequest,
4+
FleetSpecResponse,
5+
GatewaySpecRequest,
6+
GatewaySpecResponse,
7+
RunSpecRequest,
8+
RunSpecResponse,
9+
SpecApplyRequest,
10+
SpecApplyResponse,
11+
VolumeSpecRequest,
12+
VolumeSpecResponse,
13+
)
14+
from dstack.plugins.builtin.rest_plugin._plugin import (
15+
PLUGIN_SERVICE_URI_ENV_VAR_NAME,
16+
CustomApplyPolicy,
17+
RESTPlugin,
18+
)

src/dstack/plugins/builtin/models.py renamed to src/dstack/plugins/builtin/rest_plugin/_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SpecApplyRequest(BaseModel, Generic[SpecType]):
1515
project: str
1616
spec: SpecType
1717

18+
# Override dict() to remove __orig_class__ attribute and avoid "TypeError: Object of type _GenericAlias is not JSON serializable"
19+
# error. This issue doesn't happen though when running the code in pytest, only when running the server.
1820
def dict(self, *args, **kwargs):
1921
d = super().dict(*args, **kwargs)
2022
d.pop("__orig_class__", None)

src/dstack/plugins/builtin/rest_plugin.py renamed to src/dstack/plugins/builtin/rest_plugin/_plugin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from dstack._internal.core.models.fleets import FleetSpec
99
from dstack._internal.core.models.gateways import GatewaySpec
1010
from dstack._internal.core.models.volumes import VolumeSpec
11-
from dstack.plugins import ApplyPolicy, Plugin, RunSpec, get_plugin_logger
12-
from dstack.plugins._models import ApplySpec
13-
from dstack.plugins.builtin.models import (
11+
from dstack.plugins import ApplyPolicy, ApplySpec, Plugin, RunSpec, get_plugin_logger
12+
from dstack.plugins.builtin.rest_plugin import (
1413
FleetSpecRequest,
1514
FleetSpecResponse,
1615
GatewaySpecRequest,

src/tests/plugins/test_rest_plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from unittest import mock
44
from unittest.mock import Mock
55

6-
import pydantic
76
import pytest
87
import pytest_asyncio
98
import requests
@@ -164,5 +163,5 @@ async def test_on_apply_plugin_service_returns_invalid_spec(
164163
mock_response.text = json.dumps({"invalid-key": "abc"})
165164
mock_response.raise_for_status = Mock()
166165
with mock.patch("requests.post", return_value=mock_response):
167-
with pytest.raises(pydantic.ValidationError):
166+
with pytest.raises(ServerClientError):
168167
policy.on_apply(user.name, project=project.name, spec=spec)

0 commit comments

Comments
 (0)