比较提交

...

1 次代码提交

作者 SHA1 备注 提交日期
Chris Elion a94e2e47 poc 5 年前
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27
      plugin_test.py

27
plugin_test.py


import sys
plugin_paths = ["/Users/chris.elion/code/mlagents-plugins/mlagentsplugins/plugins"]
for p in plugin_paths:
sys.path.insert(1, p)
import importlib
import pkgutil
from mlagents.trainers.stats import StatsWriter
original_StatsWriters = set(StatsWriter.__subclasses__())
discovered_plugins = {
name: importlib.import_module(name)
for finder, name, ispkg in pkgutil.iter_modules(plugin_paths)
}
print(discovered_plugins)
all_StatsWriters = set(StatsWriter.__subclasses__()) # finds the new subclass
new_StatsWriters = all_StatsWriters - original_StatsWriters
print(f"Found new StatsWriters: {new_StatsWriters}")
# Instantiate the discovered classes and call them
for cls in new_StatsWriters:
sw: StatsWriter = cls()
sw.write_text("category", "I'm a new plugin", 42)
正在加载...
取消
保存