euporie.core.utils.root_module

euporie.core.utils.root_module(name: str) ModuleType

Find and load the root module of a given module name by traversing up the module hierarchy.

This function walks up the module hierarchy until it finds the topmost parent module that has a valid location. It uses Python’s importlib machinery to inspect module specifications and load modules.

Parameters:

name – The name of the module to find the root for (e.g., ‘package.subpackage.module’)

Returns:

The loaded root module object

Example

>>> root = root_module("django.contrib.admin")
>>> print(root.__name__)
'django'

Note

The function is cached using lru_cache to improve performance for repeated lookups. The function handles both regular packages and frozen modules.