diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-05-24 11:41:20 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-05-25 11:06:09 -0400 |
commit | 11521c6db7facf0703a6037948fdcc1f69cd6246 (patch) | |
tree | 7932f53483ac8999157b074767ca7e3a0781e5b5 | |
parent | 2c806099c7d581b4181acd3ecffac42bed223bea (diff) | |
download | meson-11521c6db7facf0703a6037948fdcc1f69cd6246.zip meson-11521c6db7facf0703a6037948fdcc1f69cd6246.tar.gz meson-11521c6db7facf0703a6037948fdcc1f69cd6246.tar.bz2 |
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.
-rwxr-xr-x | mesonbuild/msubprojects.py | 2 | ||||
-rw-r--r-- | mesonbuild/utils/universal.py | 34 | ||||
-rw-r--r-- | mesonbuild/wrap/wrap.py | 4 |
3 files changed, 27 insertions, 13 deletions
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py index dd9f125..db9db85 100755 --- a/mesonbuild/msubprojects.py +++ b/mesonbuild/msubprojects.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: diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index fc217c8..956b150 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -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 diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 06335ce..9e423ea 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -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'': |