Skip to content

Commit c74902d

Browse files
authored
Merge pull request #79 from codelion/add-plugins
Add plugins
2 parents 30e095f + b075d8c commit c74902d

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include optillm/plugins/*.py

optillm.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,59 @@ def get_config():
103103
plugin_approaches = {}
104104

105105
def load_plugins():
106-
plugin_dir = os.path.join(os.path.dirname(__file__), 'optillm/plugins')
107-
plugin_files = glob.glob(os.path.join(plugin_dir, '*.py'))
108-
109-
for plugin_file in plugin_files:
110-
module_name = os.path.basename(plugin_file)[:-3] # Remove .py extension
111-
spec = importlib.util.spec_from_file_location(module_name, plugin_file)
112-
module = importlib.util.module_from_spec(spec)
113-
spec.loader.exec_module(module)
114-
115-
if hasattr(module, 'SLUG') and hasattr(module, 'run'):
116-
plugin_approaches[module.SLUG] = module.run
117-
logger.info(f"Loaded plugin: {module.SLUG}")
106+
# Clear existing plugins first but modify the global dict in place
107+
plugin_approaches.clear()
108+
109+
# Get installed package plugins directory
110+
import optillm
111+
package_plugin_dir = os.path.join(os.path.dirname(optillm.__file__), 'plugins')
112+
113+
# Get local project plugins directory
114+
current_dir = os.getcwd()
115+
local_plugin_dir = os.path.join(current_dir, 'optillm', 'plugins')
116+
117+
plugin_dirs = []
118+
119+
# Add package plugin dir
120+
plugin_dirs.append((package_plugin_dir, "package"))
121+
122+
# Add local plugin dir only if it's different from package dir
123+
if local_plugin_dir != package_plugin_dir:
124+
plugin_dirs.append((local_plugin_dir, "local"))
125+
126+
for plugin_dir, source in plugin_dirs:
127+
logger.info(f"Looking for {source} plugins in: {plugin_dir}")
128+
129+
if not os.path.exists(plugin_dir):
130+
logger.debug(f"{source.capitalize()} plugin directory not found: {plugin_dir}")
131+
continue
132+
133+
plugin_files = glob.glob(os.path.join(plugin_dir, '*.py'))
134+
if not plugin_files:
135+
logger.debug(f"No plugin files found in {source} directory: {plugin_dir}")
136+
continue
137+
138+
logger.info(f"Found {source} plugin files: {plugin_files}")
139+
140+
for plugin_file in plugin_files:
141+
try:
142+
module_name = os.path.basename(plugin_file)[:-3] # Remove .py extension
143+
spec = importlib.util.spec_from_file_location(module_name, plugin_file)
144+
module = importlib.util.module_from_spec(spec)
145+
spec.loader.exec_module(module)
146+
147+
if hasattr(module, 'SLUG') and hasattr(module, 'run'):
148+
if module.SLUG in plugin_approaches:
149+
logger.info(f"Overriding {source} plugin: {module.SLUG}")
150+
plugin_approaches[module.SLUG] = module.run
151+
logger.info(f"Loaded {source} plugin: {module.SLUG}")
152+
else:
153+
logger.warning(f"Plugin {module_name} from {source} missing required attributes (SLUG and run)")
154+
except Exception as e:
155+
logger.error(f"Error loading {source} plugin {plugin_file}: {str(e)}")
156+
157+
if not plugin_approaches:
158+
logger.warning("No plugins loaded from any location")
118159

119160
def parse_combined_approach(model: str, known_approaches: list, plugin_approaches: dict):
120161
if model == 'auto':

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
setup(
44
name="optillm",
5-
version="0.0.5",
5+
version="0.0.6",
66
packages=find_packages(),
77
py_modules=['optillm'],
8+
package_data={
9+
'optillm': ['plugins/*.py'], # Include plugin files
10+
},
11+
include_package_data=True, # This is important
812
install_requires=[
913
"numpy",
1014
"networkx",

0 commit comments

Comments
 (0)