Skip to content

Commit 42474c1

Browse files
Attempt ot fix AssertionError: "OntoEnv directory not found at: "./.ontoenv"" does not match "OntoEnv directory not found at: ".\.ontoenv"" on Windows
1 parent 9cb6ada commit 42474c1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

python/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ fn anyhow_to_pyerr(e: Error) -> PyErr {
2323
PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string())
2424
}
2525

26+
// Helper function to format paths with forward slashes for cross-platform error messages
27+
fn format_path_for_error(path: &std::path::Path) -> String {
28+
path.to_string_lossy().replace('\\', "/")
29+
}
30+
2631
#[allow(dead_code)]
2732
struct MyTerm(Term);
2833
impl From<Result<Bound<'_, PyAny>, pyo3::PyErr>> for MyTerm {
@@ -217,11 +222,10 @@ impl OntoEnv {
217222
// Check if OntoEnv() is called without any meaningful arguments
218223
// This implements the behavior expected by the tests
219224
if path.is_none() && root == "." && !recreate && !temporary {
220-
let dot_ontoenv_path = PathBuf::from(".").join(".ontoenv");
221-
return Err(PyValueError::new_err(format!(
222-
"OntoEnv directory not found at: \"{}\"",
223-
dot_ontoenv_path.display()
224-
)));
225+
// Use forward slashes for cross-platform compatibility in error messages
226+
return Err(PyValueError::new_err(
227+
"OntoEnv directory not found at: \"./.ontoenv\""
228+
));
225229
}
226230
let mut root_path = path.clone().unwrap_or_else(|| PathBuf::from(root));
227231
// If the provided path points to a '.ontoenv' directory, treat its parent as the root
@@ -282,13 +286,13 @@ impl OntoEnv {
282286
if path.is_some() {
283287
return Err(PyValueError::new_err(format!(
284288
"OntoEnv directory not found at: \"{}\"",
285-
root_path.join(".ontoenv").display()
289+
format_path_for_error(&root_path.join(".ontoenv"))
286290
)));
287291
}
288292
if read_only {
289293
return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
290294
"OntoEnv directory not found at: \"{}\" and read_only=True",
291-
root_path.join(".ontoenv").to_string_lossy()
295+
format_path_for_error(&root_path.join(".ontoenv"))
292296
)));
293297
}
294298
OntoEnvRs::init(cfg, false).map_err(anyhow_to_pyerr)?

0 commit comments

Comments
 (0)