From f29a453b2109dadcd948ce9fbe8020389bb1e6ee Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 17 Aug 2024 12:54:35 -0700 Subject: [PATCH] prevent progress indicator from overwriting interactive git ssh output --- src/poetry/puzzle/provider.py | 6 ++++++ src/poetry/utils/pause_indicator.py | 20 ++++++++++++++++++++ src/poetry/vcs/git/backend.py | 12 +++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/poetry/utils/pause_indicator.py diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index 754795b845c..b6e37a16bd1 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -29,6 +29,7 @@ from poetry.puzzle.exceptions import OverrideNeeded from poetry.repositories.exceptions import PackageNotFound from poetry.utils.helpers import get_file_hash +from poetry.utils import pause_indicator if TYPE_CHECKING: @@ -105,6 +106,11 @@ def _formatter_elapsed(self) -> str: return f"{elapsed:.1f}s" + def _display(self, *args, **kwargs): + if pause_indicator.is_paused(): + return + super()._display(*args, **kwargs) + class Provider: UNSAFE_PACKAGES: ClassVar[set[str]] = set() diff --git a/src/poetry/utils/pause_indicator.py b/src/poetry/utils/pause_indicator.py new file mode 100644 index 00000000000..a405509f885 --- /dev/null +++ b/src/poetry/utils/pause_indicator.py @@ -0,0 +1,20 @@ + +from threading import Lock + +_lock = Lock() +_counter = 0 + +def is_paused(): + return _counter != 0 + +class IndicatorPaused: + def __enter__(self): + global _counter + with _lock: + _counter += 1 + + def __exit__(self, *exc): + global _counter + with _lock: + _counter -= 1 + assert _counter >= 0 diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index 0fc00f0b266..203604fff1f 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -24,6 +24,7 @@ from poetry.console.exceptions import PoetryConsoleError from poetry.utils.authenticator import get_default_authenticator from poetry.utils.helpers import remove_directory +from poetry.utils.pause_indicator import IndicatorPaused if TYPE_CHECKING: @@ -207,11 +208,12 @@ def _fetch_remote_refs(cls, url: str, local: Repo) -> FetchPackResult: client, path = get_transport_and_path(url, config=config, **kwargs) with local: - result: FetchPackResult = client.fetch( - path, - local, - determine_wants=local.object_store.determine_wants_all, - ) + with IndicatorPaused(): + result: FetchPackResult = client.fetch( + path, + local, + determine_wants=local.object_store.determine_wants_all, + ) return result @staticmethod