Skip to content

Recursive subpackage/submodule walk #2

@thorwhalen

Description

@thorwhalen

See aix/sk.py. It uses guide.tools.submodule_callables, but that function doesn't catch everything (seems to fail on __all__ definitions.

"""sklearn (scikit-learn)"""
from contextlib import suppress
from guide.tools import submodule_callables

import sklearn

for _ in list(dict.fromkeys(submodule_callables(sklearn))):
    if hasattr(_, '__name__'):
        locals()[_.__name__] = _

for _subpackage_name in sklearn.__all__:
    with suppress(ModuleNotFoundError):
        _subpackage = __import__(f"sklearn.{_subpackage_name}")
        for _ in submodule_callables(sklearn):
            if hasattr(_, '__name__'):
                locals()[_.__name__] = _

See: https://github.com/thorwhalen/guide/blob/master/guide/tools.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions