]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/cli/command_context.py
1 from contextlib
import ExitStack
, contextmanager
2 from typing
import ContextManager
, Generator
, TypeVar
4 _T
= TypeVar("_T", covariant
=True)
7 class CommandContextMixIn
:
8 def __init__(self
) -> None:
10 self
._in
_main
_context
= False
11 self
._main
_context
= ExitStack()
14 def main_context(self
) -> Generator
[None, None, None]:
15 assert not self
._in
_main
_context
17 self
._in
_main
_context
= True
19 with self
._main
_context
:
22 self
._in
_main
_context
= False
24 def enter_context(self
, context_provider
: ContextManager
[_T
]) -> _T
:
25 assert self
._in
_main
_context
27 return self
._main
_context
.enter_context(context_provider
)