This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Django inspired component loading (#719)
- Loading branch information
Showing
8 changed files
with
67 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import importlib | ||
|
||
|
||
def load_class_from_path(path_and_class: str): | ||
""" | ||
Dynamically load a class from a module at the specified path | ||
Args: | ||
path_and_class: relative path where to find the module and its class name | ||
i.e. 'neo.<package>.<package>.<module>.<class name>' | ||
Raises: | ||
ValueError: if the Module or Class is not found. | ||
Returns: | ||
class object | ||
""" | ||
try: | ||
module_path = '.'.join(path_and_class.split('.')[:-1]) | ||
module = importlib.import_module(module_path) | ||
except ImportError as err: | ||
raise ValueError(f"Failed to import module {module_path} with error: {err}") | ||
|
||
try: | ||
class_name = path_and_class.split('.')[-1] | ||
class_obj = getattr(module, class_name) | ||
return class_obj | ||
except AttributeError as err: | ||
raise ValueError(f"Failed to get class {class_name} with error: {err}") |
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