Skip to content

Commit 3891af1

Browse files
committed
[Docs] Fix gen_schema_reference.py on Python 3.10
Allows to generate docs on Python 3.10, which is still supported by dstack. In addition, str Enum representation on Python 3.11+ was fixed.
1 parent 90c00cf commit 3891af1

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,20 @@ dev = [
153153
"pytest-xdist>=3.6.1",
154154
"pyinstrument>=5.0.0",
155155
"kubernetes-stubs-elephant-fork",
156-
# docs
157-
"dstack[server]; python_version >= '3.11'",
158-
"dstack-plugin-server; python_version >= '3.11'",
159-
"pillow; python_version >= '3.11'",
160-
"cairosvg; python_version >= '3.11'",
161-
"mkdocs-material>=9.7.0; python_version >= '3.11'",
162-
"mkdocs-material[imaging]; python_version >= '3.11'",
163-
"mkdocs-material-extensions; python_version >= '3.11'",
164-
"mkdocs-redirects; python_version >= '3.11'",
165-
"mkdocs-gen-files; python_version >= '3.11'",
166-
"mkdocstrings[python]; python_version >= '3.11'",
167-
"mkdocs-render-swagger-plugin; python_version >= '3.11'",
156+
{include-group = "docs"},
157+
]
158+
docs = [
159+
"dstack[server]",
160+
"dstack-plugin-server",
161+
"pillow",
162+
"cairosvg",
163+
"mkdocs-material>=9.7.0",
164+
"mkdocs-material[imaging]",
165+
"mkdocs-material-extensions",
166+
"mkdocs-redirects",
167+
"mkdocs-gen-files",
168+
"mkdocstrings[python]",
169+
"mkdocs-render-swagger-plugin",
168170
]
169171

170172
[project.optional-dependencies]

scripts/docs/gen_schema_reference.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727

2828
def _is_linkable_type(annotation: Any) -> bool:
2929
"""Check if a type annotation contains a BaseModel subclass (excluding Range)."""
30-
if inspect.isclass(annotation):
31-
return issubclass(annotation, BaseModel) and not issubclass(annotation, Range)
3230
origin = get_origin(annotation)
31+
type_ = origin if origin is not None else annotation
32+
if inspect.isclass(type_):
33+
return issubclass(type_, BaseModel) and not issubclass(type_, Range)
3334
if origin is Annotated:
3435
return _is_linkable_type(get_args(annotation)[0])
3536
if origin is Union:
@@ -239,12 +240,12 @@ def generate_schema_reference(
239240
default_repr = None
240241
elif isinstance(default, (list, tuple, dict)) and len(default) == 0:
241242
default_repr = None
242-
elif isinstance(default, str):
243-
default_repr = default
244-
elif isinstance(default, BaseModel):
245-
default_repr = str(default)
246243
elif isinstance(default, Enum):
247244
default_repr = str(default.value)
245+
elif isinstance(default, BaseModel):
246+
default_repr = str(default)
247+
elif isinstance(default, str):
248+
default_repr = default
248249
else:
249250
default_repr = json.dumps(default)
250251
friendly_type = get_friendly_type(field.annotation)

0 commit comments

Comments
 (0)