Spaces:
Runtime error
Runtime error
File size: 2,838 Bytes
b115d50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
import json
from enum import Enum
from typing import Dict, List, Optional, Type, Union
from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr
from steamship.base.error import SteamshipError
class ConfigParameterType(str, Enum):
NUMBER = "number"
STRING = "string"
BOOLEAN = "boolean"
@staticmethod
def from_python_type(t: Type):
if issubclass(t, str):
return ConfigParameterType.STRING
elif issubclass(t, bool): # bool is a subclass of int, so must do this first!
return ConfigParameterType.BOOLEAN
elif issubclass(t, float) or issubclass(t, int):
return ConfigParameterType.NUMBER
else:
raise SteamshipError(f"Unknown value type in Config: {t}")
class ConfigParameter(BaseModel):
type: ConfigParameterType
description: Optional[str] = None
# Use strict so that Pydantic doesn't coerce values into the first one that fits
default: Optional[Union[StrictStr, StrictBool, StrictFloat, StrictInt]] = None
class DeployableType(str, Enum):
PLUGIN = "plugin"
PACKAGE = "package"
class SteamshipRegistry(BaseModel):
tagline: Optional[str] # noqa: N815
tagline2: Optional[str] # noqa: N815
usefulFor: Optional[str] # noqa: N815
videoUrl: Optional[str] # noqa: N815
githubUrl: Optional[str] # noqa: N815
demoUrl: Optional[str] # noqa: N815
blogUrl: Optional[str] # noqa: N815
jupyterUrl: Optional[str] # noqa: N815
authorGithub: Optional[str] # noqa: N815
authorName: Optional[str] # noqa: N815
authorEmail: Optional[str] # noqa: N815
authorTwitter: Optional[str] # noqa: N815
authorUrl: Optional[str] # noqa: N815
tags: List[str]
class PluginConfig(BaseModel):
isTrainable: Optional[bool] = False # noqa: N815
transport: str = "jsonOverHttp"
type: str # Does not use PluginType due to circular import
class Manifest(BaseModel):
type: DeployableType
handle: str
version: str
description: Optional[str]
author: Optional[str]
entrypoint: str = "Unused"
public: bool
plugin: Optional[PluginConfig]
build_config: Dict[str, List[str]] = {"ignore": []}
configTemplate: Optional[Dict[str, ConfigParameter]] # noqa: N815
steamshipRegistry: SteamshipRegistry # noqa: N815
@staticmethod
def load_manifest() -> "Manifest":
return Manifest.parse_file("steamship.json", content_type="application/json")
def save(self):
with open("steamship.json", "w") as file:
json.dump(self.dict(), file, indent="\t")
def config_template_as_dict(self):
result = {}
for param, spec in self.configTemplate.items():
result[param] = {k: v for k, v in spec.dict().items() if v is not None}
return result
|