Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions automated_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
import typing

# Fake modules to avoid import errors
for module_name in ("requests", "unidecode"):
sys.modules[module_name] = object()

requests = type(sys)("requests")
requests.__dict__["Response"] = type(
"Response", (), {"__module__": "requests"}
)

sys.modules["requests"] = requests
sys.modules["unidecode"] = type(sys)("unidecode")

import ayon_api # noqa: E402
from ayon_api.server_api import ServerAPI, _PLACEHOLDER # noqa: E402
Expand Down Expand Up @@ -116,7 +122,32 @@ def prepare_docstring(func):

def _get_typehint(annotation, api_globals):
if inspect.isclass(annotation):
return annotation.__name__
module_name_parts = list(str(annotation.__module__).split("."))
module_name_parts.append(annotation.__name__)
module_name_parts.reverse()
options = []
_name = None
for name in module_name_parts:
if _name is None:
_name = name
options.append(name)
else:
_name = f"{name}.{_name}"
options.append(_name)

options.reverse()
for option in options:
try:
# Test if typehint is valid for known '_api' content
exec(f"_: {option} = None", api_globals)
return option
except NameError:
pass

typehint = options[0]
print("Unknown typehint:", typehint)
typehint = f'"{typehint}"'
return typehint

typehint = (
str(annotation)
Expand Down
2 changes: 2 additions & 0 deletions ayon_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
get_project_anatomy_presets,
get_default_anatomy_preset_name,
get_project_anatomy_preset,
get_built_in_anatomy_preset,
get_build_in_anatomy_preset,
get_project_root_overrides,
get_project_roots_by_site,
Expand Down Expand Up @@ -366,6 +367,7 @@
"get_project_anatomy_presets",
"get_default_anatomy_preset_name",
"get_project_anatomy_preset",
"get_built_in_anatomy_preset",
"get_build_in_anatomy_preset",
"get_project_root_overrides",
"get_project_roots_by_site",
Expand Down
Loading
Loading