replaced the previous venv system by a conda one, allowing for better dependencies management
This commit is contained in:
parent
8bf28e4c48
commit
0034c7b31a
17 changed files with 313 additions and 230 deletions
|
@ -1,24 +1,5 @@
|
|||
import inspect
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
# the list of types and their name that can be used by the API
|
||||
types: dict[str, type] = {
|
||||
"bool": bool,
|
||||
"int": int,
|
||||
"float": float,
|
||||
"str": str,
|
||||
"bytes": bytes,
|
||||
"dict": dict,
|
||||
"datetime": datetime,
|
||||
"file": UploadFile,
|
||||
|
||||
# TODO(Faraphel): use a "ParameterRegistry" or other functions to handle complex type ?
|
||||
"list[dict]": list[dict],
|
||||
# "tuple": tuple,
|
||||
# "set": set,
|
||||
}
|
||||
import fastapi
|
||||
|
||||
|
||||
def load(parameters_definition: dict[str, dict]) -> list[inspect.Parameter]:
|
||||
|
@ -31,7 +12,6 @@ def load(parameters_definition: dict[str, dict]) -> list[inspect.Parameter]:
|
|||
>>> parameters_definition = {
|
||||
... "boolean": {"type": "bool", "default": False},
|
||||
... "list": {"type": "list", "default": [1, 2, 3]},
|
||||
... "datetime": {"type": "datetime"},
|
||||
... "file": {"type": "file"},
|
||||
... }
|
||||
>>> parameters = load_parameters(parameters_definition)
|
||||
|
@ -40,12 +20,19 @@ def load(parameters_definition: dict[str, dict]) -> list[inspect.Parameter]:
|
|||
parameters: list[inspect.Parameter] = []
|
||||
|
||||
for name, definition in parameters_definition.items():
|
||||
# preprocess the type
|
||||
match definition["type"]:
|
||||
case "file":
|
||||
# shortcut for uploading a file
|
||||
definition["type"] = fastapi.UploadFile
|
||||
|
||||
|
||||
# deserialize the parameter
|
||||
parameter = inspect.Parameter(
|
||||
name,
|
||||
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
||||
default=definition.get("default", inspect.Parameter.empty),
|
||||
annotation=types[definition["type"]],
|
||||
annotation=definition["type"],
|
||||
)
|
||||
parameters.append(parameter)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue