Source code for flat_export.sub3

# -*- coding: utf-8 -*-
"""Test module for sub-module name promotion in package.

>>> _import_mode_
'direct'

>>> sub1_func()
# sub1 !

>>> sub2_func()
# sub2 !

"""

_package_imports_ = [
    ('flat_export', '.', 'sub1', 'sub1_func'), # from .sub1 import sub1_func
    ('flat_export', '.', '',     'sub2_func'), # from .     import sub2_func
]

try:
    for _p, _r, _m, _i in _package_imports_:
        exec("from " + ''.join((_r, _m)) + " import " + _i)
    _import_mode_ = 'internal'
except (SyntaxError, SystemError, ValueError, ImportError):
    try:
        for _p, _r, _m, _i in _package_imports_:
            if not _m:
                _pm = _p
            else:
                _pm = '.'.join((_p, _m))
            exec("from " + _pm + " import " + _i)
        _import_mode_ = 'package'
    except ImportError:
        import os
        import sys
        for _p, _r, _m, _i in _package_imports_:
            if not _m:
                _r += '.'
                _m = _p.split('.').pop()
            _m_dir = os.path.abspath(os.path.dirname(__file__))
            while len(_r) > 2:
                _m_dir = os.path.abspath(os.path.join(_m_dir, os.path.pardir))
            if len(_r) == 2:
                _m_dir = os.path.abspath(os.path.join(_m_dir, os.path.pardir))
            if _m_dir not in sys.path:
                sys.path.append(_m_dir)
            exec("from " + _m + " import " + _i)
        _import_mode_ = 'direct'

__all__ = []

__all__.append('sub3_func')
[docs]def sub3_func(): """Example function in module `sub1`.""" print('# sub3 !')
if __name__ == '__main__': print('# sub3 doctest') def _hidden_test(locals_): del(locals_['_hidden_test']) import doctest doctest.testmod() _hidden_test(locals()) print('_import_mode_: ' + str(_import_mode_)) # :ide: COMPILE: Run with PYTHONPATH=.. w/o script args # . (progn (save-buffer) (compile (concat "PYTHONPATH=.. python ./" (file-name-nondirectory (buffer-file-name)) " "))) # :ide: COMPILE: Run with python3 w/o args # . (progn (save-buffer) (compile (concat "python3 ./" (file-name-nondirectory (buffer-file-name)) " "))) # :ide: COMPILE: Run w/o args # . (progn (save-buffer) (compile (concat "python ./" (file-name-nondirectory (buffer-file-name)) " ")))