Skip to content

Commit df4817d

Browse files
committed
Improve logging
1 parent 3e40e95 commit df4817d

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

crates/red_knot_python_semantic/src/module_resolver/path.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,19 @@ impl PartialEq<SearchPath> for VendoredPathBuf {
633633
}
634634
}
635635

636+
impl fmt::Display for SearchPath {
637+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
638+
match &*self.0 {
639+
SearchPathInner::Extra(system_path_buf)
640+
| SearchPathInner::FirstParty(system_path_buf)
641+
| SearchPathInner::SitePackages(system_path_buf)
642+
| SearchPathInner::Editable(system_path_buf)
643+
| SearchPathInner::StandardLibraryCustom(system_path_buf) => system_path_buf.fmt(f),
644+
SearchPathInner::StandardLibraryVendored(vendored_path_buf) => vendored_path_buf.fmt(f),
645+
}
646+
}
647+
}
648+
636649
#[cfg(test)]
637650
mod tests {
638651
use ruff_db::Db;

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Cow;
2+
use std::fmt;
23
use std::iter::FusedIterator;
34
use std::str::Split;
45

@@ -611,11 +612,17 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
611612
// stubs package doesn't exist, continue with the regular package
612613
}
613614
Err(PackageKind::Regular) => {
615+
tracing::trace!(
616+
"Stub-package in `{search_path} doesn't contain module: `{name}`"
617+
);
614618
// stub exists, but the module doesn't.
615619
// TODO: Support partial packages.
616620
return None;
617621
}
618622
Err(PackageKind::Namespace) => {
623+
tracing::trace!(
624+
"Stub-package in `{search_path} doesn't contain module: `{name}` but it is a namespace package, keep going."
625+
);
619626
// stub exists, but the module doesn't. But this is a namespace package,
620627
// keep searchig the next search path for a stub package with the same name.
621628
continue;
@@ -625,13 +632,20 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
625632

626633
match resolve_module_in_search_path(&resolver_state, &name, search_path) {
627634
Ok((file, kind)) => return Some((search_path.clone(), ResolvedModule { kind, file })),
628-
Err(kind) => {
629-
// For regular packages, don't search the next search path. All files of that
630-
// package must be in the same location
631-
if kind.is_regular_package() {
635+
Err(kind) => match kind {
636+
PackageKind::Root => {}
637+
PackageKind::Regular => {
638+
// For regular packages, don't search the next search path. All files of that
639+
// package must be in the same location
640+
tracing::trace!("Package in `{search_path} doesn't contain module: `{name}`");
632641
return None;
633642
}
634-
}
643+
PackageKind::Namespace => {
644+
tracing::trace!(
645+
"Package in `{search_path} doesn't contain module: `{name}` but it is a namespace package, keep going."
646+
);
647+
}
648+
},
635649
}
636650
}
637651

@@ -787,12 +801,6 @@ enum PackageKind {
787801
Namespace,
788802
}
789803

790-
impl PackageKind {
791-
const fn is_regular_package(self) -> bool {
792-
matches!(self, PackageKind::Regular)
793-
}
794-
}
795-
796804
pub(super) struct ResolverContext<'db> {
797805
pub(super) db: &'db dyn Db,
798806
pub(super) python_version: PythonVersion,
@@ -830,6 +838,12 @@ impl RelaxedModuleName {
830838
}
831839
}
832840

841+
impl fmt::Display for RelaxedModuleName {
842+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
843+
self.0.fmt(f)
844+
}
845+
}
846+
833847
#[cfg(test)]
834848
mod tests {
835849
use ruff_db::files::{system_path_to_file, File, FilePath};

0 commit comments

Comments
 (0)