pub fn retain_modules_for_importer<T>(
project: &dyn Project,
importer: &ProjectFile,
candidates: &mut Vec<T>,
source_of: impl Fn(&T) -> &ProjectFile,
)Expand description
Keep only the candidates an absolute import written in importer can mean.
A Python module name is path-derived and relative to an import root, so one
snapshot that vendors two distributions side by side spells the same module
twice: Feathr’s registry/purview-registry/registry/models.py and
registry/sql-registry/registry/models.py are both registry.models
(#3475). Python resolves an absolute import against the sys.path entries
the importing program runs with, and the entry always on it is the root the
importing file itself lives under, so that root’s module is the one the
import means. An enclosing root qualifies as well as the importer’s own
package root, which is what lets a distribution’s top-level script import
its own packages; when more than one qualifies, the nearest one shadows the
rest the way a closer sys.path entry does.
A candidate set that no containing root owns survives whole. That leaves a genuine cross-root import resolvable and keeps the ambiguity visible to whichever caller asked for a unique identity, rather than inventing a preference the workspace does not state.