Skip to content

Commit

Permalink
don't add all folders to the path
Browse files Browse the repository at this point in the history
  • Loading branch information
brownben committed Nov 12, 2024
1 parent 38ded82 commit f508b82
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl Trackback {
pub fn compile_file(file: &path::Path) -> Result<PyObject, Error> {
let file = &file.canonicalize().expect("file to exist");

add_all_parent_modules_to_path(file);
add_parent_module_to_path(file);
capture_stdout_stderr();

let file_name: CString = filename_to_cstring(file);
Expand Down Expand Up @@ -472,18 +472,13 @@ fn add_to_sys_modules_path(path: &CStr) {
}
}

/// Adds the given path and any parent paths which are Python files to
/// Python's module resolution path variable.
///
/// Used to ensure that a test module can be found no matter how it is specified.
fn add_all_parent_modules_to_path(file: &path::Path) {
if file.is_dir() {
add_to_sys_modules_path(&path_to_cstring(file));
}

if is_python_module(file) {
if let Some(parent) = file.parent() {
add_all_parent_modules_to_path(parent);
/// Adds the lowest parent path which is not python module to the module search path.
fn add_parent_module_to_path(file: &path::Path) {
if let Some(parent) = file.parent() {
if is_python_module(parent) {
add_parent_module_to_path(parent);
} else {
add_to_sys_modules_path(&path_to_cstring(parent));
}
}
}
Expand Down

0 comments on commit f508b82

Please sign in to comment.