-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5837316
commit c72d379
Showing
16 changed files
with
156 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
"""Contains a factory helper.""" | ||
from __future__ import annotations | ||
|
||
import importlib | ||
import asyncio | ||
from importlib import import_module | ||
import logging | ||
from typing import Any | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def factory(class_path: str, **kwargs: Any) -> Any: | ||
"""Return class instance from the class path.""" | ||
async def create_instance(class_path: str, **kwargs: Any) -> Any: | ||
"""Return a class instance from the class path.""" | ||
loop = asyncio.get_running_loop() | ||
module_name, class_name = class_path.rsplit(".", 1) | ||
try: | ||
module_name, class_name = class_path.rsplit(".", 1) | ||
return getattr( | ||
importlib.import_module("." + module_name, "pyplumio"), class_name | ||
)(**kwargs) | ||
module = await loop.run_in_executor( | ||
None, import_module, "." + module_name, "pyplumio" | ||
) | ||
return getattr(module, class_name)(**kwargs) | ||
except Exception: | ||
_LOGGER.error("Failed to load module (%s)", class_path) | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.