2023-10-19 06:51:55 +00:00
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
from importlib.util import module_from_spec, spec_from_file_location
|
|
|
|
from pathlib import Path
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2024-03-11 12:01:48 +00:00
|
|
|
from invokeai.app.services.config.config_default import get_config
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2024-03-11 12:06:55 +00:00
|
|
|
custom_nodes_path = Path(get_config().custom_nodes_path)
|
2023-10-19 06:51:55 +00:00
|
|
|
custom_nodes_path.mkdir(parents=True, exist_ok=True)
|
2023-10-20 01:50:55 +00:00
|
|
|
|
2023-10-19 06:51:55 +00:00
|
|
|
custom_nodes_init_path = str(custom_nodes_path / "__init__.py")
|
2023-10-20 01:50:55 +00:00
|
|
|
custom_nodes_readme_path = str(custom_nodes_path / "README.md")
|
2023-10-19 06:51:55 +00:00
|
|
|
|
|
|
|
# copy our custom nodes __init__.py to the custom nodes directory
|
2023-10-20 01:50:55 +00:00
|
|
|
shutil.copy(Path(__file__).parent / "custom_nodes/init.py", custom_nodes_init_path)
|
|
|
|
shutil.copy(Path(__file__).parent / "custom_nodes/README.md", custom_nodes_readme_path)
|
2023-10-19 06:51:55 +00:00
|
|
|
|
|
|
|
# Import custom nodes, see https://docs.python.org/3/library/importlib.html#importing-programmatically
|
|
|
|
spec = spec_from_file_location("custom_nodes", custom_nodes_init_path)
|
|
|
|
if spec is None or spec.loader is None:
|
|
|
|
raise RuntimeError(f"Could not load custom nodes from {custom_nodes_init_path}")
|
|
|
|
module = module_from_spec(spec)
|
|
|
|
sys.modules[spec.name] = module
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
|
|
|
|
# add core nodes to __all__
|
2023-10-20 01:50:55 +00:00
|
|
|
python_files = filter(lambda f: not f.name.startswith("_"), Path(__file__).parent.glob("*.py"))
|
2023-11-10 23:44:43 +00:00
|
|
|
__all__ = [f.stem for f in python_files] # type: ignore
|