Use lazy imports in __init__.py (#3847)
This commit is contained in:
committed by
GitHub
parent
b2a24baa0f
commit
c78ee6a8d0
@@ -1,7 +1,10 @@
|
|||||||
from ddtrace import tracer
|
|
||||||
from ddtrace.trace import TraceFilter, Span
|
|
||||||
from ddtrace.ext import http
|
|
||||||
import re
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from ddtrace import tracer
|
||||||
|
from ddtrace.ext import http
|
||||||
|
from ddtrace.trace import TraceFilter, Span
|
||||||
|
|
||||||
from skyvern.forge.sdk.forge_log import setup_logger
|
from skyvern.forge.sdk.forge_log import setup_logger
|
||||||
|
|
||||||
|
|
||||||
@@ -20,38 +23,7 @@ class FilterHeartbeat(TraceFilter):
|
|||||||
tracer.configure(trace_processors=[FilterHeartbeat()])
|
tracer.configure(trace_processors=[FilterHeartbeat()])
|
||||||
setup_logger()
|
setup_logger()
|
||||||
|
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
from skyvern.forge import app # noqa: E402, F401
|
|
||||||
from skyvern.library import Skyvern # noqa: E402
|
|
||||||
from skyvern.core.script_generations.skyvern_page import RunContext, SkyvernPage # noqa: E402
|
|
||||||
from skyvern.core.script_generations.run_initializer import setup # noqa: E402
|
|
||||||
from skyvern.core.script_generations.workflow_wrappers import ( # noqa: E402
|
|
||||||
cached, # noqa: E402
|
|
||||||
workflow, # noqa: E402
|
|
||||||
) # noqa: E402
|
|
||||||
from skyvern.services.script_service import ( # noqa: E402
|
|
||||||
action, # noqa: E402
|
|
||||||
download, # noqa: E402
|
|
||||||
extract, # noqa: E402
|
|
||||||
http_request, # noqa: E402
|
|
||||||
goto, # noqa: E402
|
|
||||||
login, # noqa: E402
|
|
||||||
loop, # noqa: E402
|
|
||||||
parse_file, # noqa: E402
|
|
||||||
parse_pdf, # noqa: E402
|
|
||||||
prompt, # noqa: E402
|
|
||||||
render_list, # noqa: E402
|
|
||||||
render_template, # noqa: E402
|
|
||||||
run_code, # noqa: E402
|
|
||||||
run_script, # noqa: E402
|
|
||||||
run_task, # noqa: E402
|
|
||||||
send_email, # noqa: E402
|
|
||||||
upload_file, # noqa: E402
|
|
||||||
validate, # noqa: E402
|
|
||||||
wait, # noqa: E402
|
|
||||||
) # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Skyvern",
|
"Skyvern",
|
||||||
"SkyvernPage",
|
"SkyvernPage",
|
||||||
@@ -79,3 +51,52 @@ __all__ = [
|
|||||||
"wait",
|
"wait",
|
||||||
"workflow",
|
"workflow",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_lazy_imports = {
|
||||||
|
"Skyvern": "skyvern.library",
|
||||||
|
"SkyvernPage": "skyvern.core.script_generations.skyvern_page",
|
||||||
|
"RunContext": "skyvern.core.script_generations.skyvern_page",
|
||||||
|
"setup": "skyvern.core.script_generations.run_initializer",
|
||||||
|
"cached": "skyvern.core.script_generations.workflow_wrappers",
|
||||||
|
"workflow": "skyvern.core.script_generations.workflow_wrappers",
|
||||||
|
"action": "skyvern.services.script_service",
|
||||||
|
"download": "skyvern.services.script_service",
|
||||||
|
"extract": "skyvern.services.script_service",
|
||||||
|
"http_request": "skyvern.services.script_service",
|
||||||
|
"goto": "skyvern.services.script_service",
|
||||||
|
"login": "skyvern.services.script_service",
|
||||||
|
"loop": "skyvern.services.script_service",
|
||||||
|
"parse_file": "skyvern.services.script_service",
|
||||||
|
"parse_pdf": "skyvern.services.script_service",
|
||||||
|
"prompt": "skyvern.services.script_service",
|
||||||
|
"render_list": "skyvern.services.script_service",
|
||||||
|
"render_template": "skyvern.services.script_service",
|
||||||
|
"run_code": "skyvern.services.script_service",
|
||||||
|
"run_script": "skyvern.services.script_service",
|
||||||
|
"run_task": "skyvern.services.script_service",
|
||||||
|
"send_email": "skyvern.services.script_service",
|
||||||
|
"upload_file": "skyvern.services.script_service",
|
||||||
|
"validate": "skyvern.services.script_service",
|
||||||
|
"wait": "skyvern.services.script_service",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def __getattr__(name: str) -> Any:
|
||||||
|
if name in _lazy_imports:
|
||||||
|
module_path = _lazy_imports[name]
|
||||||
|
from importlib import import_module # noqa: PLC0415
|
||||||
|
|
||||||
|
module = import_module(module_path)
|
||||||
|
|
||||||
|
# For attributes that need to be extracted from the module
|
||||||
|
if hasattr(module, name):
|
||||||
|
value = getattr(module, name)
|
||||||
|
else:
|
||||||
|
# For module-level imports like "app"
|
||||||
|
value = module
|
||||||
|
|
||||||
|
# Cache the imported value
|
||||||
|
globals()[name] = value
|
||||||
|
return value
|
||||||
|
|
||||||
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
from skyvern.library.skyvern import Skyvern
|
from typing import Any
|
||||||
|
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
__all__ = ["Skyvern"]
|
__all__ = ["Skyvern"]
|
||||||
|
|
||||||
|
|
||||||
|
def __getattr__(name: str) -> Any:
|
||||||
|
"""Lazily import Skyvern."""
|
||||||
|
if name == "Skyvern":
|
||||||
|
from skyvern.library.skyvern import Skyvern # noqa: PLC0415
|
||||||
|
|
||||||
|
globals()["Skyvern"] = Skyvern
|
||||||
|
return Skyvern
|
||||||
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||||
|
|||||||
Reference in New Issue
Block a user