Skip to content

Question regarding the main GRAPE module import #32

Open
@RemyLau

Description

@RemyLau

Hi! One minor question/suggestion: I'm wondering if it would be a better idea not to load all modules as is done right now. For example, when I want to load from the local module utils.py, it fails because utils was taken by ensmallen. One way I've tried to work around this is to pop the automatically loaded ensmallen utils module by sys.modules.pop['utils'].

grape/grape/__init__.py

Lines 13 to 30 in 788e195

def import_all(module_locals):
"""Execute dynamic loading of submodules."""
import ensmallen as _ensmallen
import embiggen as _embiggen
import sys as _sys
import pkgutil as _pkgutil
for _module in (_ensmallen, _embiggen):
for _loader, _module_name, _is_pkg in _pkgutil.iter_modules(_module.__path__):
if not _is_pkg:
continue
if _module_name.startswith(("_", "~")):
continue
_loaded_module = _loader.find_module(
_module_name
).load_module(_module_name)
_sys.modules[f'grape.{_module_name}'] = _loaded_module
module_locals[_module_name] = _loaded_module

Would it be better to simply do the following instead of importing everything?

import embiggen
import ensmallen

__all__ = ["embiggne", "ensmallen"]  # or add whatever top level modules that make sense

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions