euporie.core.utils

Miscellaneous utility classes.

Functions

cache(user_function, /)

Simple lightweight unbounded cache.

dict_merge(target_dict, input_dict)

Merge the second dictionary onto the first.

import_submodules(root, names)

Import all submodules with a specific name within a root module's package hierarchy.

on_click(func)

Return a mouse handler which call a given function on click.

overload(func)

Decorator for overloaded functions/methods.

root_module(name)

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

Classes

ChainedList(*lists)

A list-like class which chains multiple lists.

MouseButton(*values)

MouseEventType(*values)

Sequence()

All the operations on a read-only sequence.

TypeVar

Type variable.

chain(*iterables)

Return a chain object whose .__next__() method returns elements from the first iterable until it is exhausted, then elements from the next iterable, until all of the iterables are exhausted.

class euporie.core.utils.ChainedList(*lists: Iterable[T])

Bases: Sequence[T]

A list-like class which chains multiple lists.

count(value) integer -- return number of occurrences of value
property data: list[T]

Return the list data.

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

euporie.core.utils.dict_merge(target_dict: dict, input_dict: dict) None

Merge the second dictionary onto the first.

euporie.core.utils.import_submodules(root: ModuleType, names: tuple[str]) list[ModuleType]

Import all submodules with a specific name within a root module’s package hierarchy.

This function walks through all packages under the given root module and imports any submodules that match the specified name. It handles various module types including regular packages, single file modules, and frozen modules.

Parameters:
  • root – The root module object to search within

  • names – The specific submodule name to search for

Returns:

A list of imported module objects matching the specified name

Example

>>> root = import_module("django")
>>> admin_modules = import_submodules(root, "admin")
>>> print([m.__name__ for m in admin_modules])
['django.contrib.admin', 'django.contrib.gis.admin']

Note

  • The function is cached using lru_cache to improve performance for repeated imports

  • For packages, it searches through __path__

  • For single file modules, it uses __file__

  • For frozen modules, it uses the module specification’s origin

euporie.core.utils.on_click(func: Callable) MouseHandler

Return a mouse handler which call a given function on click.

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.