ProgressBar: Fix some rendering issues

- Do not hardcode terminal width of 100 chars, that breaks rendering on
  smaller terminal. It already uses current console width by default.
- Disable progress bar when downloading from msubprojects because it
  fetches multiple wraps in parallel.
- Scale unit when downloading e.g. MB/s.
- Do not display rate when it's not a download.
- Do not display time elapsed to simplify the rendering.
pull/11818/head
Xavier Claessens 2 years ago committed by Eli Schwartz
parent 2c806099c7
commit 11521c6db7
  1. 2
      mesonbuild/msubprojects.py
  2. 34
      mesonbuild/utils/universal.py
  3. 4
      mesonbuild/wrap/wrap.py

@ -693,7 +693,7 @@ def run(options: 'Arguments') -> int:
if not os.path.isdir(subprojects_dir):
mlog.log('Directory', mlog.bold(src_dir), 'does not seem to have subprojects.')
return 0
r = Resolver(src_dir, 'subprojects', wrap_frontend=True, allow_insecure=options.allow_insecure)
r = Resolver(src_dir, 'subprojects', wrap_frontend=True, allow_insecure=options.allow_insecure, silent=True)
if options.subprojects:
wraps = [wrap for name, wrap in r.wraps.items() if name in options.subprojects]
else:

@ -1893,17 +1893,20 @@ class ProgressBarFallback: # lgtm [py/iter-returns-non-self]
__iter__ method' warning.
'''
def __init__(self, iterable: T.Optional[T.Iterable[str]] = None, total: T.Optional[int] = None,
bar_type: T.Optional[str] = None, desc: T.Optional[str] = None):
bar_type: T.Optional[str] = None, desc: T.Optional[str] = None,
disable: T.Optional[bool] = None):
if iterable is not None:
self.iterable = iter(iterable)
return
self.total = total
self.done = 0
self.printed_dots = 0
if self.total and bar_type == 'download':
print('Download size:', self.total)
if desc:
print(f'{desc}: ', end='')
self.disable = not mlog.colorize_console() if disable is None else disable
if not self.disable:
if self.total and bar_type == 'download':
print('Download size:', self.total)
if desc:
print(f'{desc}: ', end='')
# Pretend to be an iterator when called as one and don't print any
# progress
@ -1914,8 +1917,9 @@ class ProgressBarFallback: # lgtm [py/iter-returns-non-self]
return next(self.iterable)
def print_dot(self) -> None:
print('.', end='')
sys.stdout.flush()
if not self.disable:
print('.', end='')
sys.stdout.flush()
self.printed_dots += 1
def update(self, progress: int) -> None:
@ -1929,7 +1933,8 @@ class ProgressBarFallback: # lgtm [py/iter-returns-non-self]
self.print_dot()
def close(self) -> None:
print('')
if not self.disable:
print()
try:
from tqdm import tqdm
@ -1940,10 +1945,17 @@ else:
class ProgressBarTqdm(tqdm):
def __init__(self, *args: T.Any, bar_type: T.Optional[str] = None, **kwargs: T.Any) -> None:
if bar_type == 'download':
kwargs.update({'unit': 'bytes', 'leave': True})
kwargs.update({'unit': 'B',
'unit_scale': True,
'unit_divisor': 1024,
'leave': True,
'bar_format': '{l_bar}{bar}| {n_fmt}/{total_fmt} {rate_fmt} eta {remaining}',
})
else:
kwargs.update({'leave': False})
kwargs['ncols'] = 100
kwargs.update({'leave': False,
'bar_format': '{l_bar}{bar}| {n_fmt}/{total_fmt} eta {remaining}',
})
super().__init__(*args, **kwargs)
ProgressBar = ProgressBarTqdm

@ -285,6 +285,7 @@ class Resolver:
wrap_mode: WrapMode = WrapMode.default
wrap_frontend: bool = False
allow_insecure: bool = False
silent: bool = False
def __post_init__(self) -> None:
self.subdir_root = os.path.join(self.source_dir, self.subdir)
@ -695,7 +696,8 @@ class Resolver:
return hashvalue, tmpfile.name
sys.stdout.flush()
progress_bar = ProgressBar(bar_type='download', total=dlsize,
desc='Downloading')
desc='Downloading',
disable=(self.silent or None))
while True:
block = resp.read(blocksize)
if block == b'':

Loading…
Cancel
Save