31
31
import sys
32
32
from contextlib import contextmanager
33
33
from importlib import import_module
34
- from types import CodeType
34
+ from typing import TYPE_CHECKING
35
35
36
36
# 3rd party
37
37
import pluggy # type: ignore
38
38
from domdf_python_tools .paths import in_directory
39
- from domdf_python_tools .typing import PathLike
40
39
from first import first
41
40
from tox import reporter # type: ignore
42
- from tox .action import Action # type: ignore
43
- from tox .config import Config , TestenvConfig # type: ignore
44
- from tox .venv import VirtualEnv # type: ignore
45
41
46
42
# this package
47
43
import tox_recreate_hook .hooks
48
44
49
- __all__ = ["append_to_sys_path" , "tox_testenv_create" ]
45
+ if TYPE_CHECKING :
46
+ # stdlib
47
+ from types import CodeType
48
+
49
+ # 3rd party
50
+ from domdf_python_tools .typing import PathLike
51
+ from tox .action import Action # type: ignore
52
+ from tox .config import Config , TestenvConfig # type: ignore
53
+ from tox .venv import VirtualEnv # type: ignore
50
54
51
55
__author__ : str = "Dominic Davis-Foster"
52
56
__copyright__ : str = "2021 Dominic Davis-Foster"
53
57
__license__ : str = "MIT License"
54
58
__version__ : str = "0.1.0"
55
59
__email__ :
str = "[email protected] "
56
60
61
+ __all__ = ["append_to_sys_path" , "tox_testenv_create" ]
62
+
57
63
hookimpl = pluggy .HookimplMarker ("tox" )
58
64
59
65
60
66
@contextmanager
61
- def append_to_sys_path (path : PathLike ):
67
+ def append_to_sys_path (path : " PathLike" ):
62
68
"""
63
69
Append ``path`` to :py:obj:`sys.path` for the scope of the :keyword:`with` block.
64
70
@@ -67,7 +73,7 @@ def append_to_sys_path(path: PathLike):
67
73
68
74
path = os .fspath (path )
69
75
70
- if path in sys .path :
76
+ if path in sys .path : # pragma: no cover
71
77
yield
72
78
return
73
79
@@ -81,10 +87,8 @@ def append_to_sys_path(path: PathLike):
81
87
82
88
83
89
@hookimpl
84
- def tox_testenv_create (venv : VirtualEnv , action : Action ) -> None : # noqa: D103
85
- envconfig : TestenvConfig = venv .envconfig
86
- config : Config = envconfig .config
87
- toxinidir = config .toxinidir
90
+ def tox_testenv_create (venv : "VirtualEnv" , action : "Action" ) -> None : # noqa: D103
91
+ envconfig : "TestenvConfig" = venv .envconfig
88
92
89
93
if not envconfig .recreate :
90
94
return
@@ -94,6 +98,9 @@ def tox_testenv_create(venv: VirtualEnv, action: Action) -> None: # noqa: D103
94
98
if not recreate_hook .strip ():
95
99
return None
96
100
101
+ config : "Config" = envconfig .config
102
+ toxinidir = config .toxinidir
103
+
97
104
# The whole process should take place within the toxinidir
98
105
with in_directory (toxinidir ):
99
106
print (f"output = { recreate_hook } " )
0 commit comments