|
16 | 16 |
|
17 | 17 | from __future__ import annotations |
18 | 18 |
|
| 19 | +# Standard Library |
| 20 | +import importlib |
| 21 | +import typing |
| 22 | +import warnings |
| 23 | + |
19 | 24 | # Local Implementation |
20 | | -from . import async_api |
21 | | -from ._helpers import mask_command |
22 | | -from ._ssh_helpers import HostsSSHConfigs |
23 | | -from ._ssh_helpers import SSHConfig |
24 | | -from .api import ExecHelper |
25 | 25 | from .exceptions import CalledProcessError |
26 | 26 | from .exceptions import ExecCalledProcessError |
27 | 27 | from .exceptions import ExecHelperError |
28 | 28 | from .exceptions import ExecHelperNoKillError |
29 | 29 | from .exceptions import ExecHelperTimeoutError |
30 | 30 | from .exceptions import ParallelCallExceptionsError |
31 | 31 | from .exceptions import ParallelCallProcessError |
32 | | -from .exec_result import ExecResult |
33 | | -from .proc_enums import ExitCodes |
34 | | -from .ssh import SSHClient |
35 | | -from .ssh_auth import SSHAuth |
36 | | -from .subprocess import Subprocess # nosec # Expected |
37 | 32 |
|
38 | 33 | try: |
39 | 34 | # Local Implementation |
40 | 35 | from ._version import version as __version__ |
41 | 36 | except ImportError: |
42 | 37 | pass |
43 | 38 |
|
| 39 | +# noinspection PyUnresolvedReferences |
44 | 40 | __all__ = ( |
45 | 41 | "ExecHelperError", |
46 | 42 | "ExecCalledProcessError", |
|
49 | 45 | "ParallelCallProcessError", |
50 | 46 | "ExecHelperNoKillError", |
51 | 47 | "ExecHelperTimeoutError", |
| 48 | + # pylint: disable=undefined-all-variable |
| 49 | + # lazy load |
| 50 | + # API |
| 51 | + "async_api", |
| 52 | + "ExitCodes", |
| 53 | + "ExecResult", |
52 | 54 | "ExecHelper", |
53 | | - "SSHClient", |
54 | 55 | "mask_command", |
| 56 | + # Expensive |
| 57 | + "Subprocess", |
| 58 | + "SSHClient", |
55 | 59 | "SSHAuth", |
56 | 60 | "SSHConfig", |
57 | 61 | "HostsSSHConfigs", |
58 | | - "Subprocess", |
59 | | - "ExitCodes", |
60 | | - "ExecResult", |
61 | | - "async_api", |
| 62 | + # deprecated |
| 63 | + "ParallelCallExceptions", |
62 | 64 | ) |
63 | 65 |
|
| 66 | +__locals: typing.Dict[str, typing.Any] = locals() # use mutable access for pure lazy loading |
| 67 | + |
| 68 | +__lazy_load_modules: typing.Sequence[str] = ("async_api",) |
| 69 | + |
| 70 | +__lazy_load_parent_modules: typing.Dict[str, str] = { |
| 71 | + "HostsSSHConfigs": "_ssh_helpers", |
| 72 | + "SSHConfig": "_ssh_helpers", |
| 73 | + "SSHClient": "ssh", |
| 74 | + "SSHAuth": "ssh_auth", |
| 75 | + "Subprocess": "subprocess", |
| 76 | + # API |
| 77 | + "ExitCodes": "proc_enums", |
| 78 | + "ExecResult": "exec_result", |
| 79 | + "ExecHelper": "api", |
| 80 | + "mask_command": "_helpers", |
| 81 | + "ParallelCallExceptions": "exceptions", |
| 82 | +} |
| 83 | + |
| 84 | +_deprecated: typing.Dict[str, str] = {"ParallelCallExceptions": "ParallelCallExceptionsError"} |
| 85 | + |
| 86 | + |
| 87 | +def __getattr__(name: str) -> typing.Any: |
| 88 | + """Get attributes lazy. |
| 89 | +
|
| 90 | + :return: attribute by name |
| 91 | + :raises AttributeError: attribute is not defined for lazy load |
| 92 | + """ |
| 93 | + if name in _deprecated: |
| 94 | + warnings.warn(f"{name} is deprecated in favor of {_deprecated[name]}", DeprecationWarning) |
| 95 | + if name in __lazy_load_modules: |
| 96 | + mod = importlib.import_module(f"{__package__}.{name}") |
| 97 | + __locals[name] = mod |
| 98 | + return mod |
| 99 | + if name in __lazy_load_parent_modules: |
| 100 | + mod = importlib.import_module(f"{__package__}.{__lazy_load_parent_modules[name]}") |
| 101 | + obj = getattr(mod, name) |
| 102 | + __locals[name] = obj |
| 103 | + return obj |
| 104 | + raise AttributeError(f"{name} not found in {__package__}") |
| 105 | + |
| 106 | + |
64 | 107 | __author__ = "Alexey Stepanov" |
65 | 108 | __author_email__ = "[email protected]" |
66 | 109 | __maintainers__ = { |
|
0 commit comments