blob: e1e0a09f1a219ef24c0263d1cbc6aa1bda3e66a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
from typing import TYPE_CHECKING, Dict, Iterable, Type
from .package import PackageToxEnv
from .runner import RunToxEnv
if TYPE_CHECKING:
from tox.plugin.manager import Plugin
class ToxEnvRegister:
def __init__(self) -> None:
self._run_envs: Dict[str, Type[RunToxEnv]] = {}
self._package_envs: Dict[str, Type[PackageToxEnv]] = {}
self._default_run_env: str = ""
def populate(self, manager: "Plugin") -> None:
manager.tox_register_tox_env(register=self)
self._default_run_env = next(iter(self._run_envs.keys()))
def add_run_env(self, of_type: Type[RunToxEnv]) -> None:
self._run_envs[of_type.id()] = of_type
def add_package_env(self, of_type: Type[PackageToxEnv]) -> None:
self._package_envs[of_type.id()] = of_type
@property
def run_envs(self) -> Iterable[str]:
return self._run_envs.keys()
@property
def default_run_env(self) -> str:
return self._default_run_env
@default_run_env.setter
def default_run_env(self, value: str) -> None:
assert value in self._run_envs, "default env must be in run envs"
self._default_run_env = value
def runner(self, name: str) -> Type[RunToxEnv]:
return self._run_envs[name]
def package(self, name: str) -> Type[PackageToxEnv]:
return self._package_envs[name]
REGISTER = ToxEnvRegister()
|