mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
b9ee4af4c6
commit
4fe72090de
16 changed files with 632 additions and 217 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue