Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
8c4ccb55
Commit
8c4ccb55
authored
Mar 11, 2023
by
comfyanonymous
Browse files
Small refactor of custom node loading code.
parent
1f717903
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
19 deletions
+24
-19
nodes.py
nodes.py
+24
-19
No files found.
nodes.py
View file @
8c4ccb55
...
@@ -948,8 +948,29 @@ NODE_CLASS_MAPPINGS = {
...
@@ -948,8 +948,29 @@ NODE_CLASS_MAPPINGS = {
"VAEDecodeTiled"
:
VAEDecodeTiled
,
"VAEDecodeTiled"
:
VAEDecodeTiled
,
}
}
CUSTOM_NODE_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"custom_nodes"
)
def
load_custom_node
(
module_path
):
module_name
=
os
.
path
.
basename
(
module_path
)
if
os
.
path
.
isfile
(
module_path
):
sp
=
os
.
path
.
splitext
(
module_path
)
module_name
=
sp
[
0
]
try
:
if
os
.
path
.
isfile
(
module_path
):
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
else
:
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
os
.
path
.
join
(
module_path
,
"__init__.py"
))
module
=
importlib
.
util
.
module_from_spec
(
module_spec
)
sys
.
modules
[
module_name
]
=
module
module_spec
.
loader
.
exec_module
(
module
)
if
hasattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
and
getattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
is
not
None
:
NODE_CLASS_MAPPINGS
.
update
(
module
.
NODE_CLASS_MAPPINGS
)
else
:
print
(
f
"Skip
{
module_path
}
module for custom nodes due to the lack of NODE_CLASS_MAPPINGS."
)
except
Exception
as
e
:
print
(
traceback
.
format_exc
())
print
(
f
"Cannot import
{
module_path
}
module for custom nodes:"
,
e
)
def
load_custom_nodes
():
def
load_custom_nodes
():
CUSTOM_NODE_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"custom_nodes"
)
possible_modules
=
os
.
listdir
(
CUSTOM_NODE_PATH
)
possible_modules
=
os
.
listdir
(
CUSTOM_NODE_PATH
)
if
"__pycache__"
in
possible_modules
:
if
"__pycache__"
in
possible_modules
:
possible_modules
.
remove
(
"__pycache__"
)
possible_modules
.
remove
(
"__pycache__"
)
...
@@ -957,22 +978,6 @@ def load_custom_nodes():
...
@@ -957,22 +978,6 @@ def load_custom_nodes():
for
possible_module
in
possible_modules
:
for
possible_module
in
possible_modules
:
module_path
=
os
.
path
.
join
(
CUSTOM_NODE_PATH
,
possible_module
)
module_path
=
os
.
path
.
join
(
CUSTOM_NODE_PATH
,
possible_module
)
if
os
.
path
.
isfile
(
module_path
)
and
os
.
path
.
splitext
(
module_path
)[
1
]
!=
".py"
:
continue
if
os
.
path
.
isfile
(
module_path
)
and
os
.
path
.
splitext
(
module_path
)[
1
]
!=
".py"
:
continue
load_custom_node
(
module_path
)
module_name
=
possible_module
load_custom_nodes
()
try
:
if
os
.
path
.
isfile
(
module_path
):
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
else
:
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
os
.
path
.
join
(
module_path
,
"__init__.py"
))
module
=
importlib
.
util
.
module_from_spec
(
module_spec
)
sys
.
modules
[
module_name
]
=
module
module_spec
.
loader
.
exec_module
(
module
)
if
hasattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
and
getattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
is
not
None
:
NODE_CLASS_MAPPINGS
.
update
(
module
.
NODE_CLASS_MAPPINGS
)
else
:
print
(
f
"Skip
{
possible_module
}
module for custom nodes due to the lack of NODE_CLASS_MAPPINGS."
)
except
Exception
as
e
:
print
(
traceback
.
format_exc
())
print
(
f
"Cannot import
{
possible_module
}
module for custom nodes:"
,
e
)
load_custom_nodes
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment