summaryrefslogtreecommitdiffstats
path: root/Tools/c-analyzer/c_common
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2020-10-30 21:46:52 (GMT)
committerGitHub <noreply@github.com>2020-10-30 21:46:52 (GMT)
commit4fe72090deb7fb7bc09bfa56c92f6b3b0967d395 (patch)
tree264fb8dec036a697595ff539ce9d3e4433224d47 /Tools/c-analyzer/c_common
parentb9ee4af4c643a323779fd7076e80b29d611f2709 (diff)
downloadcpython-4fe72090deb7fb7bc09bfa56c92f6b3b0967d395.zip
cpython-4fe72090deb7fb7bc09bfa56c92f6b3b0967d395.tar.gz
cpython-4fe72090deb7fb7bc09bfa56c92f6b3b0967d395.tar.bz2
bpo-36876: Small adjustments to the C-analyzer tool. (GH-23045)
This is a little bit of clean-up, small fixes, and additional helpers prior to building an updated & accurate list of globals to eliminate.
Diffstat (limited to 'Tools/c-analyzer/c_common')
-rw-r--r--Tools/c-analyzer/c_common/scriptutil.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/Tools/c-analyzer/c_common/scriptutil.py b/Tools/c-analyzer/c_common/scriptutil.py
index 939a850..2220590 100644
--- a/Tools/c-analyzer/c_common/scriptutil.py
+++ b/Tools/c-analyzer/c_common/scriptutil.py
@@ -10,6 +10,9 @@ import sys
from . import fsutil, strutil, iterutil, logging as loggingutil
+_NOT_SET = object()
+
+
def get_prog(spec=None, *, absolute=False, allowsuffix=True):
if spec is None:
_, spec = _find_script()
@@ -313,6 +316,22 @@ def _parse_files(filenames):
yield filename.strip()
+def add_progress_cli(parser, *, threshold=VERBOSITY, **kwargs):
+ parser.add_argument('--progress', dest='track_progress', action='store_const', const=True)
+ parser.add_argument('--no-progress', dest='track_progress', action='store_false')
+ parser.set_defaults(track_progress=True)
+
+ def process_args(args):
+ if args.track_progress:
+ ns = vars(args)
+ verbosity = ns.get('verbosity', VERBOSITY)
+ if verbosity <= threshold:
+ args.track_progress = track_progress_compact
+ else:
+ args.track_progress = track_progress_flat
+ return process_args
+
+
def add_failure_filtering_cli(parser, pool, *, default=False):
parser.add_argument('--fail', action='append',
metavar=f'"{{all|{"|".join(sorted(pool))}}},..."')
@@ -551,13 +570,39 @@ def _iter_filenames(filenames, iter_files):
raise NotImplementedError
-def iter_marks(mark='.', *, group=5, groups=2, lines=10, sep=' '):
+def track_progress_compact(items, *, groups=5, **mark_kwargs):
+ last = os.linesep
+ marks = iter_marks(groups=groups, **mark_kwargs)
+ for item in items:
+ last = next(marks)
+ print(last, end='', flush=True)
+ yield item
+ if not last.endswith(os.linesep):
+ print()
+
+
+def track_progress_flat(items, fmt='<{}>'):
+ for item in items:
+ print(fmt.format(item), flush=True)
+ yield item
+
+
+def iter_marks(mark='.', *, group=5, groups=2, lines=_NOT_SET, sep=' '):
mark = mark or ''
+ group = group if group and group > 1 else 1
+ groups = groups if groups and groups > 1 else 1
+
sep = f'{mark}{sep}' if sep else mark
end = f'{mark}{os.linesep}'
div = os.linesep
perline = group * groups
- perlines = perline * lines
+ if lines is _NOT_SET:
+ # By default we try to put about 100 in each line group.
+ perlines = 100 // perline * perline
+ elif not lines or lines < 0:
+ perlines = None
+ else:
+ perlines = perline * lines
if perline == 1:
yield end
@@ -568,7 +613,7 @@ def iter_marks(mark='.', *, group=5, groups=2, lines=10, sep=' '):
while True:
if count % perline == 0:
yield end
- if count % perlines == 0:
+ if perlines and count % perlines == 0:
yield div
elif count % group == 0:
yield sep