Skip to content

Commit 575299d

Browse files
committed
add the option to specify the configuration path
1 parent 70027ee commit 575299d

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

docs/local_conf.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,17 @@ export ETHOPY_DB_PASSWORD="your_secret_password"
309309
Then in your config file, you can leave the password field empty - EthoPy will use the environment variable instead.
310310

311311
### Custom Configuration Locations
312-
By default, EthoPy looks for configuration in `~/.ethopy/local_conf.json`. If you need to use a different location, you can specify it when starting EthoPy (ask your technical support person for help with this).
312+
By default, EthoPy looks for configuration in `~/.ethopy/local_conf.json`. You can specify a different configuration file using the `--config` option:
313+
314+
```bash
315+
# Use a custom configuration file
316+
ethopy --config /path/to/my_config.json
317+
318+
# Or use the short form
319+
ethopy -c /path/to/my_config.json
320+
```
321+
322+
This is useful when you want to:
323+
- Switch between different experimental setups
324+
- Test with different database configurations
325+
- Keep separate configurations for different projects

src/ethopy/cli.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
type=int,
2727
help="Task ID from database",
2828
)
29+
@click.option(
30+
"-c",
31+
"--config",
32+
type=click.Path(exists=True),
33+
help="Path to configuration file (default: ~/.ethopy/local_conf.json)",
34+
)
2935
@click.option(
3036
"--log-console",
3137
is_flag=True,
@@ -38,11 +44,18 @@
3844
)
3945
@click.version_option()
4046
def main(
41-
task_path: Path, task_id: int, log_console: bool, log_level: str = None
47+
task_path: Path, task_id: int, config: str, log_console: bool, log_level: str = None
4248
) -> None:
4349
"""EthoPy - Behavioral Training Control System."""
44-
# Load configuration
45-
local_conf = ConfigurationManager()
50+
# Load configuration (custom or default)
51+
if config:
52+
# Create configuration manager with custom config file
53+
local_conf = ConfigurationManager(config_file=config)
54+
# Update the global configuration with the custom settings
55+
local_conf.update_global_config()
56+
else:
57+
# Use default configuration
58+
local_conf = ConfigurationManager()
4659

4760
# Set a configuration value
4861
if not log_level:

src/ethopy/config.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,35 @@ def update(self, updates: Dict[str, Any]) -> None:
197197
"""Update multiple configuration values at once."""
198198
for key, value in updates.items():
199199
self.set(key, value)
200+
201+
def update_global_config(self) -> None:
202+
"""Update the global EthoPy configuration with this instance's settings.
203+
204+
This method updates the global configuration state used throughout EthoPy,
205+
including DataJoint settings, schema mappings, and plugin manager.
206+
Useful for CLI applications that need to override global configuration.
207+
"""
208+
try:
209+
import ethopy
210+
import datajoint as dj
211+
from ethopy.plugin_manager import PluginManager
212+
213+
# Update the global configuration instance
214+
ethopy.local_conf = self
215+
216+
# Update DataJoint configuration with this instance's settings
217+
dj_config = self.get("dj_local_conf", {})
218+
dj.config.update(dj_config)
219+
dj.logger.setLevel(dj_config.get("datajoint.loglevel", "WARNING"))
220+
221+
# Update global schema mappings
222+
ethopy.SCHEMATA = self.get("SCHEMATA", {})
223+
224+
# Update plugin manager with new plugin path
225+
ethopy.plugin_manager = PluginManager(self.get("plugin_path"))
226+
227+
self.logging.info(f"Updated configuration from {self.config_file}")
228+
229+
except Exception as e:
230+
self.logging.error(f"Error updating configuration: {e}")
231+
raise

0 commit comments

Comments
 (0)