Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/cli/command_context.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:47:31 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9e54283cc701 |
|---|---|
| 1 from contextlib import contextmanager | |
| 2 | |
| 3 from pip._vendor.contextlib2 import ExitStack | |
| 4 | |
| 5 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
| 6 | |
| 7 if MYPY_CHECK_RUNNING: | |
| 8 from typing import Iterator, ContextManager, TypeVar | |
| 9 | |
| 10 _T = TypeVar('_T', covariant=True) | |
| 11 | |
| 12 | |
| 13 class CommandContextMixIn(object): | |
| 14 def __init__(self): | |
| 15 # type: () -> None | |
| 16 super(CommandContextMixIn, self).__init__() | |
| 17 self._in_main_context = False | |
| 18 self._main_context = ExitStack() | |
| 19 | |
| 20 @contextmanager | |
| 21 def main_context(self): | |
| 22 # type: () -> Iterator[None] | |
| 23 assert not self._in_main_context | |
| 24 | |
| 25 self._in_main_context = True | |
| 26 try: | |
| 27 with self._main_context: | |
| 28 yield | |
| 29 finally: | |
| 30 self._in_main_context = False | |
| 31 | |
| 32 def enter_context(self, context_provider): | |
| 33 # type: (ContextManager[_T]) -> _T | |
| 34 assert self._in_main_context | |
| 35 | |
| 36 return self._main_context.enter_context(context_provider) |
