pub struct PythonModuleResolver { /* private fields */ }Expand description
Resolves Python import statements to file paths.
Builds an index of module dotted names → file paths from a root directory.
Handles absolute imports and relative imports (e.g., from .utils import X).
Implementations§
Source§impl PythonModuleResolver
impl PythonModuleResolver
Sourcepub fn from_root(root: &Path) -> Result<Self, ResolverError>
pub fn from_root(root: &Path) -> Result<Self, ResolverError>
Build a resolver from a Python package root directory.
Walks the directory tree, discovering all .py files and building
the dotted-name → path index.
Sourcepub fn resolve_import(
&self,
import_stmt: &str,
from_file: Option<&Path>,
) -> Option<PathBuf>
pub fn resolve_import( &self, import_stmt: &str, from_file: Option<&Path>, ) -> Option<PathBuf>
Resolve an import statement to a file path, if possible.
§Arguments
import_stmt: the module name as it appears in source. For relative imports (starting with.), thefrom_filecontext is required. Examples:"brain.perception.signal_fusion",".utils","..models"from_file: the file that contains the import (needed for relative resolution). Should be a path relative toroot. IfNone, relative imports fail.
§Returns
The absolute file path if resolvable, None otherwise.
Sourcepub fn module_count(&self) -> usize
pub fn module_count(&self) -> usize
Number of modules in the index.
Sourcepub fn knows_module(&self, dotted: &str) -> bool
pub fn knows_module(&self, dotted: &str) -> bool
Whether the given dotted module name is known.
Auto Trait Implementations§
impl Freeze for PythonModuleResolver
impl RefUnwindSafe for PythonModuleResolver
impl Send for PythonModuleResolver
impl Sync for PythonModuleResolver
impl Unpin for PythonModuleResolver
impl UnsafeUnpin for PythonModuleResolver
impl UnwindSafe for PythonModuleResolver
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more