Plugin System¶
The Ethopy plugin system provides a flexible way to extend the functionality by adding custom modules, behaviors, experiments, interfaces, and stimuli. The system supports both core modules and user plugins with intelligent conflict resolution.
Plugin Categories¶
Ethopy supports two types of plugins:
- Standalone Modules: Individual Python files in the plugin directory
- Categorized Plugins: Modules organized in specific categories:
-
behaviors
: Custom behavior implementations -experiments
: Experiment definitions -interfaces
: Hardware interface modules -stimuli
: Stimulus control modules
Plugin Locations¶
Plugins can be placed in the following locations (in order of precedence):
-
Default locations:
~/.ethopy/ethopy_plugins/
(User's home directory)
-
Custom locations specified by the
ETHOPY_PLUGIN_PATH
environment variable:1
export ETHOPY_PLUGIN_PATH=/path/to/plugins,/another/plugin/path
The plugin directory structure should follow this pattern:
1 2 3 4 5 6 7 8 9 10 11 |
|
Creating Plugins¶
Plugin Naming¶
Plugins are imported using the ethopy
namespace. For example:
- Standalone module: ethopy.mymodule
- Categorized plugin: ethopy.behaviors.custom_behavior
Make sure to avoid naming conflicts with core Ethopy modules, as core modules take precedence over plugins.
Standalone Modules¶
Create a Python file in the root of your plugin directory:
1 2 3 4 5 6 7 |
|
Behavior Plugins¶
Create a Python file in the behaviors
directory:
1 2 3 4 5 6 7 8 9 10 11 |
|
Experiment Plugins¶
Create a Python file in the experiments
directory:
1 2 3 4 5 6 7 8 9 10 11 |
|
Plugin Registration¶
Plugins are automatically discovered and registered when:
1. They are placed in a recognized plugin directory
2. The file name doesn't start with an underscore
3. The file has a .py
extension
Using Plugins¶
Importing Plugins¶
Import and use plugins just like regular Ethopy modules:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Plugin Management¶
The plugin system is managed by the PluginManager
class, which handles:
- Plugin discovery and registration
- Import path management
- Conflict resolution
- Plugin information tracking
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Plugin Resolution¶
Load Order¶
Plugins are loaded in the following order: 1. Core Ethopy modules (from main package) 2. Default plugin directories 3. Custom plugin paths from environment variable
Conflict Resolution¶
The plugin system uses the following precedence rules:
-
Core vs Plugin Conflicts: - Core Ethopy modules always take precedence over plugins - Warning is issued when a plugin conflicts with a core module
-
Plugin vs Plugin Conflicts: - Later added paths take precedence over earlier ones - Warning is displayed showing which version is used/ignored
Example conflict warning:
1 2 3 4 5 |
|
Best Practices¶
Plugin Development¶
-
Namespace Awareness: - Avoid using names that conflict with core Ethopy modules - Use descriptive, unique names for your plugins - Follow Python naming conventions
-
Structure and Organization: - Place plugins in the correct category directory - Use appropriate base classes for each plugin type - Keep plugin files focused and single-purpose
-
Documentation: - Add docstrings to your plugin classes and methods - Include usage examples in the documentation - Document any special requirements or dependencies
-
Error Handling: - Implement proper error handling in your plugins - Provide meaningful error messages - Handle resource cleanup properly
Plugin Distribution¶
-
Dependencies: - Clearly specify any additional dependencies - Use standard Python package management - Test with different Python versions
-
Version Control: - Use version control for your plugins - Tag releases with version numbers - Maintain a changelog
-
Testing: - Write tests for your plugins - Test integration with Ethopy - Verify behavior with different configurations
Troubleshooting¶
Common Issues¶
-
Plugin Not Found: - Verify plugin directory location - Check file permissions - Ensure correct Python path - Validate plugin file naming
-
Import Errors: - Check for missing dependencies - Verify Python version compatibility - Look for syntax errors in plugin code - Check for circular imports
-
Plugin Conflicts: - Review plugin naming for conflicts - Check plugin path order - Examine duplicate warnings - Verify core module conflicts
Debugging Tips¶
-
Enable Debug Logging:
1 2
import logging logging.getLogger('ethopy').setLevel(logging.DEBUG)
-
Check Plugin Registration:
1 2 3 4 5 6 7 8 9 10
# List all registered plugins plugins = plugin_manager.list_plugins(show_duplicates=True) # Check specific plugin info = plugin_manager.get_plugin_info('ethopy.mymodule') if info: print(f"Plugin registered at: {info.path}") print(f"Plugin type: {info.type}") else: print("Plugin not registered")
-
Verify Plugin Paths:
1 2 3 4
# Print current plugin search paths print("Plugin paths:") for path in plugin_manager._plugin_paths: print(f"- {path}")
Additional Resources¶
-
Documentation: - Ethopy Core Documentation - DataJoint Documentation - Python Packaging Guide
-
Community: - GitHub Issues - Contributing Guidelines