Skip to content

Commit 7e0d05d

Browse files
committed
adjust python init behavior
1 parent 9e79e1d commit 7e0d05d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

python/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,20 @@ impl OntoEnv {
190190
});
191191

192192
let config_path = path.unwrap_or_else(|| PathBuf::from("."));
193-
let env = if let Some(c) = config {
193+
let env = if let Some(c) = config {
194194
// if temporary is true, create a new OntoEnv
195195
if c.cfg.temporary {
196196
OntoEnvRs::init(c.cfg, recreate).map_err(anyhow_to_pyerr)
197-
} else if !recreate {
197+
} else if !recreate && config_path.join(".ontoenv").exists() {
198198
// if temporary is false, load from the directory
199-
OntoEnvRs::load_from_directory(config_path, read_only)
200-
.map_err(anyhow_to_pyerr)
199+
OntoEnvRs::load_from_directory(config_path, read_only).map_err(anyhow_to_pyerr)
201200
} else {
202-
// if temporary is false and recreate is true, create a new OntoEnv
201+
// if temporary is false and recreate is true or the directory doesn't exist, create a new OntoEnv
203202
OntoEnvRs::init(c.cfg, recreate).map_err(anyhow_to_pyerr)
204203
}
205204
} else {
206205
// If no config but a valid path is given, attempt to load from the directory
207-
OntoEnvRs::load_from_directory(config_path, read_only)
208-
.map_err(anyhow_to_pyerr)
206+
OntoEnvRs::load_from_directory(config_path, read_only).map_err(anyhow_to_pyerr)
209207
}?;
210208

211209
let inner = Arc::new(Mutex::new(env));

0 commit comments

Comments
 (0)