Skip to content

Commit

Permalink
Made sure module_discovery.py made it into the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed Aug 9, 2022
1 parent ecd6312 commit c0cda82
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ lib/*
!lib/cqgi_interface.py
!lib/selector_synthesis
!lib/synthesis.py
!lib/module_discovery.py
addons/pythonscript/venv
addons/pythonscript/x11-64
addons/pythonscript/osx-64
Expand Down
34 changes: 34 additions & 0 deletions lib/module_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from godot import exposed, Node, Array
from pkgutil import iter_modules
from importlib import import_module

@exposed
class discovery(Node):
def discover(self, package_dir):
mods = Array()

package_dir = str(package_dir)

for (loader, module_name, is_pkg) in iter_modules([package_dir]):
if is_pkg:
if module_name == "checks":
continue
# print(module_name)
for (loader2, module_name2, is_pkg2) in iter_modules([package_dir + "/" + module_name]):
# print(" " + module_name2)

sys.path.append(package_dir)

# spec=importlib.util.spec_from_file_location(module_name2, package_dir + "/" + module_name + "/" + module_name2 + ".py")
# module = importlib.util.module_from_spec(spec)

# module = import_module("{}.{}".format(__name__, module_name))
module = import_module(module_name + "." + module_name2)
for attribute_name in dir(module):
if attribute_name.startswith("build_"):
mods.append(module_name + "." + module_name2 + "." + attribute_name)
# print(module_name + "." + module_name2 + "." + attribute_name)
# attribute = getattr(module, attribute_name)

return mods

0 comments on commit c0cda82

Please sign in to comment.