|
18 | 18 | import functools |
19 | 19 | import importlib.machinery |
20 | 20 | import io |
| 21 | +import itertools |
21 | 22 | import json |
22 | 23 | import os |
23 | 24 | import pathlib |
|
56 | 57 | if typing.TYPE_CHECKING: # pragma: no cover |
57 | 58 | from typing import Any, Callable, DefaultDict, Dict, List, Literal, Optional, Sequence, TextIO, Tuple, Type, TypeVar, Union |
58 | 59 |
|
59 | | - from mesonpy._compat import Collection, Iterator, Mapping, ParamSpec, Path |
| 60 | + from mesonpy._compat import Collection, Iterator, Mapping, ParamSpec, Path, Self |
60 | 61 |
|
61 | 62 | P = ParamSpec('P') |
62 | 63 | T = TypeVar('T') |
@@ -194,6 +195,26 @@ def _showwarning( |
194 | 195 | _log(f'{style.WARNING}meson-python: warning:{style.RESET} {message}') |
195 | 196 |
|
196 | 197 |
|
| 198 | +class _clicounter: |
| 199 | + def __init__(self, total: int) -> None: |
| 200 | + self._total = total |
| 201 | + self._count = itertools.count(start=1) |
| 202 | + |
| 203 | + def __enter__(self) -> Self: |
| 204 | + return self |
| 205 | + |
| 206 | + def update(self, description: str) -> None: |
| 207 | + line = f'[{next(self._count)}/{self._total}] {description}' |
| 208 | + if _use_ansi_escapes(): |
| 209 | + print('\r', line, sep='', end='\33[0K', flush=True) |
| 210 | + else: |
| 211 | + print(line) |
| 212 | + |
| 213 | + def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None: |
| 214 | + if _use_ansi_escapes(): |
| 215 | + print() |
| 216 | + |
| 217 | + |
197 | 218 | class Error(RuntimeError): |
198 | 219 | def __str__(self) -> str: |
199 | 220 | return str(self.args[0]) |
@@ -441,7 +462,7 @@ def build(self, directory: Path) -> pathlib.Path: |
441 | 462 | with mesonpy._wheelfile.WheelFile(wheel_file, 'w') as whl: |
442 | 463 | self._wheel_write_metadata(whl) |
443 | 464 |
|
444 | | - with mesonpy._util.clicounter(sum(len(x) for x in self._manifest.values())) as counter: |
| 465 | + with _clicounter(sum(len(x) for x in self._manifest.values())) as counter: |
445 | 466 |
|
446 | 467 | root = 'purelib' if self._pure else 'platlib' |
447 | 468 |
|
|
0 commit comments