mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-21 11:00:31 +00:00
Remove all unwrap
calls from the resolver (#5426)
This commit is contained in:
parent
4d90a5a9bc
commit
864f50a3a4
4 changed files with 47 additions and 50 deletions
|
@ -1,7 +1,7 @@
|
|||
//! Support for native Python extension modules.
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Returns `true` if the given file extension is that of a native module.
|
||||
pub(crate) fn is_native_module_file_extension(file_extension: &OsStr) -> bool {
|
||||
|
@ -36,6 +36,18 @@ pub(crate) fn is_native_module_file_name(module_name: &str, file_name: &Path) ->
|
|||
native_module_name(file_name) == Some(module_name)
|
||||
}
|
||||
|
||||
/// Find the native module within the namespace package at the given path.
|
||||
pub(crate) fn find_native_module(dir_path: &Path) -> Option<PathBuf> {
|
||||
let module_name = dir_path.file_name()?.to_str()?;
|
||||
dir_path
|
||||
.read_dir()
|
||||
.ok()?
|
||||
.flatten()
|
||||
.filter(|entry| entry.file_type().map_or(false, |ft| ft.is_file()))
|
||||
.map(|entry| entry.path())
|
||||
.find(|path| is_native_module_file_name(module_name, path))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue