src/aoikhotkeydep/aoikimportutil.py
def load_obj(
    uri,
    mod_name=None,
    sys_use=True,
    sys_add=True,
    mod_attr_sep='::',
    attr_chain_sep='.',
    retn_mod=False,
    uri_parts=None,
):
    """Load an object from a module (specified by module name in Python
    namespace)
     or from a module file (specified by module file path).

    @param uri: an uri specifying which object to load.
    An |uri| consists of two parts: |module uri| and |attr chain|,
     e.g. |a/b/c.py::x.y.z| or |a.b.c::x.y.z|

    # module uri
    |a/b/c.py| or |a.b.c| is the |module uri| part.
    Can be either a file path or a module name in Python namespace.
    Whether it is a file path is determined by whether it ends with |.py|.

    # attr chain
    |x.y.z| is attribute chain on the module object specified by module uri.

    @param mod_name: module name to be imported as.
    Only applies when |uri| specifies a module file path, not a module name.
    If None, the module file's name is used.
     E.g. |path/to/hello.py| gets module name |hello|.

    @param sys_use: see func |import_module_by_code|'s same name arg.

    @param sys_add: see func |import_module_by_code|'s same name arg.

    @param mod_attr_sep: see func |load_obj|'s same name arg.

    @param attr_chain_sep: see func |load_obj|'s same name arg.

    @retn_mod: see func |load_obj|'s same name arg.
    """
    #
    if uri_parts is None:
        uri_parts = uri_split(uri=uri, mod_attr_sep=mod_attr_sep)

    prot, mod_uri, attr_chain = uri_parts

    #
    # This means the uri specifies a module name, e.g. |a.b.c|
    if prot == 'py':
        #
        mod_name_to_load = mod_uri
        # avoid naming collision with func arg |mod_name|.
        #
        # arg |mod_name| is not used when importing by module name.
        # the name of the module to import is specified in arg |uri|.

        #
        mod_obj = import_module_by_name(
            mod_name_to_load,
            sys_use=sys_use,
            sys_add=sys_add,
        )
        # raise error

    # This means the uri specifies a module file path, e.g. |/a/b/c.py|
    else:
        #
        mod_file_path = mod_uri

        #
        if not mod_name:
            _, mod_file_name = os.path.split(mod_file_path)

            mod_name, _ = os.path.splitext(mod_file_name)

        #
        mod_obj = import_module_by_path(
            mod_file_path,
            mod_name=mod_name,
            sys_use=sys_use,
            sys_add=sys_add,
        )
        # raise error

    #
    if not attr_chain:
        if retn_mod:
            return mod_obj, None
        else:
            return mod_obj

    #
    # assert attr_chain

    attr_obj = getattr_chain(
        obj=mod_obj,
        attr_chain=attr_chain,
        sep=attr_chain_sep,
    )
    # raise error

    #
    if retn_mod:
        return mod_obj, attr_obj
    else:
        return attr_obj
Load an object from a module (specified by module name in Python
    namespace)
     or from a module file (specified by module file path).

    @param uri: an uri specifying which object to load.
    An |uri| consists of two parts: |module uri| and |attr chain|,
     e.g. |a/b/c.py::x.y.z| or |a.b.c::x.y.z|

    # module uri
    |a/b/c.py| or |a.b.c| is the |module uri| part.
    Can be either a file path or a module name in Python namespace.
    Whether it is a file path is determined by whether it ends with |.py|.

    # attr chain
    |x.y.z| is attribute chain on the module object specified by module uri.

    @param mod_name: module name to be imported as.
    Only applies when |uri| specifies a module file path, not a module name.
    If None, the module file's name is used.
     E.g. |path/to/hello.py| gets module name |hello|.

    @param sys_use: see func |import_module_by_code|'s same name arg.

    @param sys_add: see func |import_module_by_code|'s same name arg.

    @param mod_attr_sep: see func |load_obj|'s same name arg.

    @param attr_chain_sep: see func |load_obj|'s same name arg.

    @retn_mod: see func |load_obj|'s same name arg.
    
Load an object from a module (specified by module name in Python
namespace)
or from a module file (specified by module file path).
Load an object from a module ( specified by module name in Python namespace ) or from a module file ( specified by module file path ) .
def load_obj(
    uri,
    mod_name=None,
    sys_use=True,
    sys_add=True,
    mod_attr_sep='::',
    attr_chain_sep='.',
    retn_mod=False,
    uri_parts=None,
):
    if uri_parts is None:
        uri_parts = uri_split(uri=uri, mod_attr_sep=mod_attr_sep)
    prot, mod_uri, attr_chain = uri_parts
     This means the uri specifies a module name, e.g. |a.b.c|
    if prot == 'py':
        mod_name_to_load = mod_uri
         avoid naming collision with func arg |mod_name|.
         arg |mod_name| is not used when importing by module name.
         the name of the module to import is specified in arg |uri|.
        mod_obj = import_module_by_name(
            mod_name_to_load,
            sys_use=sys_use,
            sys_add=sys_add,
        )
         raise error
     This means the uri specifies a module file path, e.g. |/a/b/c.py|
    else:
        mod_file_path = mod_uri
        if not mod_name:
            _, mod_file_name = os.path.split(mod_file_path)
            mod_name, _ = os.path.splitext(mod_file_name)
        mod_obj = import_module_by_path(
            mod_file_path,
            mod_name=mod_name,
            sys_use=sys_use,
            sys_add=sys_add,
        )
         raise error
    if not attr_chain:
        if retn_mod:
            return mod_obj, None
        else:
            return mod_obj
     assert attr_chain
    attr_obj = getattr_chain(
        obj=mod_obj,
        attr_chain=attr_chain,
        sep=attr_chain_sep,
    )
     raise error
    if retn_mod:
        return mod_obj, attr_obj
    else:
        return attr_obj
def load_obj ( uri , mod_name = None , sys_use = True , sys_add = True , mod_attr_sep = '::' , attr_chain_sep = '.' , retn_mod = False , uri_parts = None , ) : if uri_parts is None : uri_parts = uri_split ( uri = uri , mod_attr_sep = mod_attr_sep ) prot , mod_uri , attr_chain = uri_parts if prot == 'py' : mod_name_to_load = mod_uri mod_obj = import_module_by_name ( mod_name_to_load , sys_use = sys_use , sys_add = sys_add , ) else : mod_file_path = mod_uri if not mod_name : _ , mod_file_name = os . path . split ( mod_file_path ) mod_name , _ = os . path . splitext ( mod_file_name ) mod_obj = import_module_by_path ( mod_file_path , mod_name = mod_name , sys_use = sys_use , sys_add = sys_add , ) if not attr_chain : if retn_mod : return mod_obj , None else : return mod_obj attr_obj = getattr_chain ( obj = mod_obj , attr_chain = attr_chain , sep = attr_chain_sep , ) if retn_mod : return mod_obj , attr_obj else : return attr_obj
Load an object from a module (specified by module name in Python
namespace)
or from a module file (specified by module file path).
Load an object from a module ( specified by module name in Python namespace ) or from a module file ( specified by module file path ) .
"""Load an object from a module (specified by module name in Python
    namespace)
     or from a module file (specified by module file path).

    @param uri: an uri specifying which object to load.
    An |uri| consists of two parts: |module uri| and |attr chain|,
     e.g. |a/b/c.py::x.y.z| or |a.b.c::x.y.z|

    # module uri
    |a/b/c.py| or |a.b.c| is the |module uri| part.
    Can be either a file path or a module name in Python namespace.
    Whether it is a file path is determined by whether it ends with |.py|.

    # attr chain
    |x.y.z| is attribute chain on the module object specified by module uri.

    @param mod_name: module name to be imported as.
    Only applies when |uri| specifies a module file path, not a module name.
    If None, the module file's name is used.
     E.g. |path/to/hello.py| gets module name |hello|.

    @param sys_use: see func |import_module_by_code|'s same name arg.

    @param sys_add: see func |import_module_by_code|'s same name arg.

    @param mod_attr_sep: see func |load_obj|'s same name arg.

    @param attr_chain_sep: see func |load_obj|'s same name arg.

    @retn_mod: see func |load_obj|'s same name arg.
    """ # # # This means the uri specifies a module name, e.g. |a.b.c| # # avoid naming collision with func arg |mod_name|. # # arg |mod_name| is not used when importing by module name. # the name of the module to import is specified in arg |uri|. # # raise error # This means the uri specifies a module file path, e.g. |/a/b/c.py| # # # # raise error # # # assert attr_chain # raise error #
uri
an uri specifying which object to load.
An |uri| consists of two parts: |module uri| and |attr chain|,
e.g.

module uri
|a/b/c.py| or |a.b.c| is the |module uri| part.
Can be either a file path or a module name in Python namespace.
Whether it is a file path is determined by whether it ends with |.py|.

attr chain
|x.y.z| is attribute chain on the module object specified by module uri.
an uri specifying which object to load . An |uri| consists of two parts : |module uri| and |attr chain| e . g . module uri |a / b / c . py| or |a . b . c| is the |module uri| part . Can be either a file path or a module name in Python namespace . Whether it is a file path is determined by whether it ends with | . py| . attr chain |x . y . z| is attribute chain on the module object specified by module uri .
mod_name
module name to be imported as.
Only applies when |uri| specifies a module file path, not a module name.
If None, the module file's name is used.
E.g. |path/to/hello.py| gets module name |hello|.
module name to be imported as . Only applies when |uri| specifies a module file path not a module name . If None the module file ' s name is used . E . g . |path / to / hello . py| gets module name |hello| .
sys_use
see func |import_module_by_code|'s same name arg.
see func |import_module_by_code| ' s same name arg .
sys_add
see func |import_module_by_code|'s same name arg.
see func |import_module_by_code| ' s same name arg .
mod_attr_sep
see func |load_obj|'s same name arg.
see func |load_obj| ' s same name arg .
attr_chain_sep
see func |load_obj|'s same name arg.
see func |load_obj| ' s same name arg .
retn_mod
uri_parts
retn_mod
see func |load_obj|'s same name arg.
see func |load_obj| ' s same name arg .