You've already forked AiraPulsar
Add basic components support
This commit is contained in:
22
pulsar/tester.py
Normal file
22
pulsar/tester.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import importlib.util
|
||||
|
||||
def run_components():
|
||||
components_dir = "components"
|
||||
for filename in os.listdir(components_dir):
|
||||
if filename.endswith(".py") and filename != "__init__.py":
|
||||
module_name = filename[:-3] # 去掉 .py 后缀
|
||||
module_path = os.path.join(components_dir, filename)
|
||||
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
if hasattr(module, "main") and callable(module.main):
|
||||
print(f"正在调用 {module_name}.main()")
|
||||
module.main()
|
||||
else:
|
||||
print(f"{module_name}.py 中没有找到 main 函数或 main 不是可调用对象。")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_components()
|
||||
Reference in New Issue
Block a user