3131import sys
3232from contextlib import contextmanager
3333from importlib import import_module
34- from types import CodeType
34+ from typing import TYPE_CHECKING
3535
3636# 3rd party
3737import pluggy # type: ignore
3838from domdf_python_tools .paths import in_directory
39- from domdf_python_tools .typing import PathLike
4039from first import first
4140from 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
4541
4642# this package
4743import tox_recreate_hook .hooks
4844
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
5054
5155__author__ : str = "Dominic Davis-Foster"
5256__copyright__ : str = "2021 Dominic Davis-Foster"
5357__license__ : str = "MIT License"
5458__version__ : str = "0.1.0"
5559__email__ : str = "dominic@davis-foster.co.uk"
5660
61+ __all__ = ["append_to_sys_path" , "tox_testenv_create" ]
62+
5763hookimpl = pluggy .HookimplMarker ("tox" )
5864
5965
6066@contextmanager
61- def append_to_sys_path (path : PathLike ):
67+ def append_to_sys_path (path : " PathLike" ):
6268 """
6369 Append ``path`` to :py:obj:`sys.path` for the scope of the :keyword:`with` block.
6470
@@ -67,7 +73,7 @@ def append_to_sys_path(path: PathLike):
6773
6874 path = os .fspath (path )
6975
70- if path in sys .path :
76+ if path in sys .path : # pragma: no cover
7177 yield
7278 return
7379
@@ -81,10 +87,8 @@ def append_to_sys_path(path: PathLike):
8187
8288
8389@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
8892
8993 if not envconfig .recreate :
9094 return
@@ -94,6 +98,9 @@ def tox_testenv_create(venv: VirtualEnv, action: Action) -> None: # noqa: D103
9498 if not recreate_hook .strip ():
9599 return None
96100
101+ config : "Config" = envconfig .config
102+ toxinidir = config .toxinidir
103+
97104 # The whole process should take place within the toxinidir
98105 with in_directory (toxinidir ):
99106 print (f"output = { recreate_hook } " )
0 commit comments