Skip to content

Commit 994e1ad

Browse files
committed
more lazy load & stubs for __init__
1 parent b33355a commit 994e1ad

File tree

7 files changed

+244
-136
lines changed

7 files changed

+244
-136
lines changed

exec_helpers/__init__.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@
2121
import typing
2222
import warnings
2323

24-
# Local Implementation
25-
from .exceptions import CalledProcessError
26-
from .exceptions import ExecCalledProcessError
27-
from .exceptions import ExecHelperError
28-
from .exceptions import ExecHelperNoKillError
29-
from .exceptions import ExecHelperTimeoutError
30-
from .exceptions import ParallelCallExceptionsError
31-
from .exceptions import ParallelCallProcessError
32-
3324
try:
3425
# Local Implementation
3526
from ._version import version as __version__
@@ -38,13 +29,6 @@
3829

3930
# noinspection PyUnresolvedReferences
4031
__all__ = (
41-
"ExecHelperError",
42-
"ExecCalledProcessError",
43-
"CalledProcessError",
44-
"ParallelCallExceptionsError",
45-
"ParallelCallProcessError",
46-
"ExecHelperNoKillError",
47-
"ExecHelperTimeoutError",
4832
# pylint: disable=undefined-all-variable
4933
# lazy load
5034
# API
@@ -59,13 +43,26 @@
5943
"SSHAuth",
6044
"SSHConfig",
6145
"HostsSSHConfigs",
46+
# Exceptions
47+
"exceptions",
48+
"ExecHelperError",
49+
"ExecCalledProcessError",
50+
"CalledProcessError",
51+
"ParallelCallExceptionsError",
52+
"ParallelCallProcessError",
53+
"ExecHelperNoKillError",
54+
"ExecHelperTimeoutError",
6255
# deprecated
6356
"ParallelCallExceptions",
6457
)
6558

6659
__locals: typing.Dict[str, typing.Any] = locals() # use mutable access for pure lazy loading
6760

68-
__lazy_load_modules: typing.Sequence[str] = ("async_api",)
61+
__lazy_load_modules: typing.Sequence[str] = (
62+
"async_api",
63+
"exceptions",
64+
"exec_result",
65+
)
6966

7067
__lazy_load_parent_modules: typing.Dict[str, str] = {
7168
"HostsSSHConfigs": "_ssh_helpers",
@@ -78,6 +75,14 @@
7875
"ExecResult": "exec_result",
7976
"ExecHelper": "api",
8077
"mask_command": "_helpers",
78+
# Exceptions
79+
"ExecHelperError": "exceptions",
80+
"ExecCalledProcessError": "exceptions",
81+
"CalledProcessError": "exceptions",
82+
"ParallelCallExceptionsError": "exceptions",
83+
"ParallelCallProcessError": "exceptions",
84+
"ExecHelperNoKillError": "exceptions",
85+
"ExecHelperTimeoutError": "exceptions",
8186
"ParallelCallExceptions": "exceptions",
8287
}
8388

exec_helpers/__init__.pyi

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2018 - 2021 Alexey Stepanov aka penguinolog.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
"""Execution helpers for simplified usage of subprocess and ssh."""
16+
17+
from __future__ import annotations
18+
19+
# Standard Library
20+
import typing
21+
22+
# Local Implementation
23+
from . import async_api
24+
from ._helpers import mask_command
25+
from ._ssh_helpers import HostsSSHConfigs
26+
from ._ssh_helpers import SSHConfig
27+
from .api import ExecHelper
28+
from .exceptions import CalledProcessError
29+
from .exceptions import ExecCalledProcessError
30+
from .exceptions import ExecHelperError
31+
from .exceptions import ExecHelperNoKillError
32+
from .exceptions import ExecHelperTimeoutError
33+
from .exceptions import ParallelCallExceptions
34+
from .exceptions import ParallelCallExceptionsError
35+
from .exceptions import ParallelCallProcessError
36+
from .exec_result import ExecResult
37+
from .proc_enums import ExitCodes
38+
from .ssh import SSHClient
39+
from .ssh_auth import SSHAuth
40+
from .subprocess import Subprocess # nosec # Expected
41+
42+
try:
43+
# Local Implementation
44+
from ._version import version as __version__
45+
except ImportError:
46+
pass
47+
48+
# noinspection PyUnresolvedReferences
49+
__all__ = (
50+
# pylint: disable=undefined-all-variable
51+
# lazy load
52+
# API
53+
"async_api",
54+
"ExitCodes",
55+
"ExecResult",
56+
"ExecHelper",
57+
"mask_command",
58+
# Expensive
59+
"Subprocess",
60+
"SSHClient",
61+
"SSHAuth",
62+
"SSHConfig",
63+
"HostsSSHConfigs",
64+
# Exceptions
65+
"ExecHelperError",
66+
"ExecCalledProcessError",
67+
"CalledProcessError",
68+
"ParallelCallExceptionsError",
69+
"ParallelCallProcessError",
70+
"ExecHelperNoKillError",
71+
"ExecHelperTimeoutError",
72+
# deprecated
73+
"ParallelCallExceptions",
74+
)
75+
76+
_deprecated: typing.Dict[str, str] = ...
77+
78+
def __getattr__(name: str) -> typing.Any:
79+
"""Get attributes lazy.
80+
81+
:return: attribute by name
82+
:raises AttributeError: attribute is not defined for lazy load
83+
"""
84+
85+
__author__: str = ...
86+
__author_email__: str = ...
87+
__maintainers__: typing.Dict[str, str] = ...
88+
__url__: str = ...
89+
__description__: str = ...
90+
__license__: str = ...
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2018 - 2021 Alexey Stepanov aka penguinolog.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
"""Execution helpers for simplified usage of subprocess. Async version.
16+
17+
.. versionadded:: 3.0.0
18+
"""
19+
20+
# noinspection PyUnresolvedReferences
21+
__all__ = (
22+
# pylint: disable=undefined-all-variable
23+
# lazy load
24+
# API
25+
"ExecHelper",
26+
"ExecResult",
27+
# Expensive
28+
"Subprocess",
29+
)
30+
31+
# Standard Library
32+
import typing
33+
34+
# Local Implementation
35+
from .api import ExecHelper
36+
from .exec_result import ExecResult
37+
from .subprocess import Subprocess # nosec # Expected
38+
39+
_deprecated: typing.Dict[str, str] = ...
40+
41+
def __getattr__(name: str) -> typing.Any:
42+
"""Get attributes lazy.
43+
44+
:return: attribute by name
45+
:raises AttributeError: attribute is not defined for lazy load
46+
"""

0 commit comments

Comments
 (0)