Skip to content

Commit

Permalink
Change client __init__ to lazy import to avoid circular imports
Browse files Browse the repository at this point in the history
Signed-off-by: Brynn Yin <[email protected]>
  • Loading branch information
brynn-code committed Apr 1, 2024
1 parent 0dc144e commit 5ac1b64
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/promptflow-devkit/promptflow/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
# ---------------------------------------------------------
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore


_imported_attr = {}


# control plane sdk functions
from promptflow._sdk._load_functions import load_flow, load_run
# Use lazy import to avoid circular import
# Circular path: PFClient -> UserAgent -> client._version -> client.__init__ -> PFClient
def __getattr__(name):
if name in _imported_attr:
return _imported_attr[name]
if name in ["PFClient", "load_run", "load_flow"]:
from promptflow._sdk._load_functions import load_flow, load_run # noqa: F401
from .._sdk._pf_client import PFClient # noqa: F401

from .._sdk._pf_client import PFClient
_imported_attr[name] = locals()[name]
return _imported_attr[name]

__all__ = ["PFClient", "load_run", "load_flow"]
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 comments on commit 5ac1b64

Please sign in to comment.