8000 Print the explanation even when the parser breaks. · python/cpython@1c1e0b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c1e0b0

Browse files
Print the explanation even when the parser breaks.
1 parent 3651ee7 commit 1c1e0b0

File tree

1 file changed

+69
-62
lines changed

1 file changed

+69
-62
lines changed

Tools/c-analyzer/c_analyzer/__main__.py

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,39 @@
4444
logger = logging.getLogger(__name__)
4545

4646

47+
EXPLANATION = textwrap.dedent('''
48+
-------------------------
49+
50+
Non-constant global variables are generally not supported
51+
in the CPython repo. We use a tool to analyze the C code
52+
and report if any unsupported globals are found. The tool
53+
may be run manually with:
54+
55+
./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]
56+
57+
Occasionally the tool is unable to parse updated code.
58+
If this happens then add the file to the "EXCLUDED" list
59+
in Tools/c-analyzer/cpython/_parser.py and create a new
60+
issue for fixing the tool (and CC ericsnowcurrently
61+
on the issue).
62+
63+
If the tool reports an unsupported global variable and
64+
it is actually const (and thus supported) then first try
65+
fixing the declaration appropriately in the code. If that
66+
doesn't work then add the variable to the "should be const"
67+
section of Tools/c-analyzer/cpython/_parser.py.
68+
69+
If the tool otherwise reports an unsupported global variable
70+
then first try to make it non-global, possibly adding to
71+
PyInterpreterState (for core code) or module state (for
72+
extension modules). In an emergency, you can add the
73+
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
74+
to get CI passing, but doing so should be avoided. If
75+
this course it taken, be sure to create an issue for
76+
eliminating the global (and CC ericsnowcurrently).
77+
''')
78+
79+
4780
#######################################
4881
# table helpers
4982

@@ -324,71 +357,45 @@ def cmd_check(filenames, *,
324357
if track_progress:
325358
filenames = track_progress(filenames)
326359

327-
logger.info('analyzing files...')
328-
analyzed = _analyze(filenames, **kwargs)
329-
analyzed.fix_filenames(relroot, normalize=False)
330-
decls = filter_forward(analyzed, markpublic=True)
331-
332-
logger.info('checking analysis results...')
333-
failed = []
334-
for data, failure in _check_all(decls, checks, failfast=failfast):
335-
if data is None:
336-
printer.info('stopping after one failure')
337-
break
338-
if div is not None and len(failed) > 0:
339-
printer.info(div)
340-
failed.append(data)
341-
handle_failure(failure, data)
342-
handle_after()
343-
344-
printer.info('-------------------------')
345-
logger.info(f'total failures: {len(failed)}')
346-
logger.info('done checking')
347-
348-
if fmt == 'summary':
349-
print('Categorized by storage:')
350-
print()
351-
from .match import group_by_storage
352-
grouped = group_by_storage(failed, ignore_non_match=False)
353-
for group, decls in grouped.items():
360+
try:
361+
logger.info('analyzing files...')
362+
analyzed = _analyze(filenames, **kwargs)
363+
analyzed.fix_filenames(relroot, normalize=False)
364+
decls = filter_forward(analyzed, markpublic=True)
365+
366+
logger.info('checking analysis results...')
367+
failed = []
368+
for data, failure in _check_all(decls, checks, failfast=failfast):
369+
if data is None:
370+
printer.info('stopping after one failure')
371+
break
372+
if div is not None and len(failed) > 0:
373+
printer.info(div)
374+
failed.append(data)
375+
handle_failure(failure, data)
376+
handle_after()
377+
378+
printer.info('-------------------------')
379+
logger.info(f'total failures: {len(failed)}')
380+
logger.info('done checking')
381+
382+
if fmt == 'summary':
383+
print('Categorized by storage:')
354384
print()
355-
print(group)
356-
for decl in decls:
357-
print(' ', _fmt_one_summary(decl))
358-
print(f'subtotal: {len(decls)}')
385+
from .match import group_by_storage
386+
grouped = group_by_storage(failed, ignore_non_match=False)
387+
for group, decls in grouped.items():
388+
print()
389+
print(group)
390+
for decl in decls:
391+
print(' ', _fmt_one_summary(decl))
392+
print(f'subtotal: {len(decls)}')
393+
except Exception:
394+
print(EXPLANATION)
395+
raise # re-raise
359396

360397
if len(failed) > 0:
361-
print(textwrap.dedent('''
362-
-------------------------
363-
364-
Non-constant global variables are generally not supported
365-
in the CPython repo. We use a tool to analyze the C code
366-
and report if any unsupported globals are found. The tool
367-
may be run manually with:
368-
369-
./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]
370-
371-
Occasionally the tool is unable to parse updated code.
372-
If this happens then add the file to the "EXCLUDED" list
373-
in Tools/c-analyzer/cpython/_parser.py and create a new
374-
issue for fixing the tool (and CC ericsnowcurrently
375-
on the issue).
376-
377-
If the tool reports an unsupported global variable and
378-
it is actually const (and thus supported) then first try
379-
fixing the declaration appropriately in the code. If that
380-
doesn't work then add the variable to the "should be const"
381-
section of Tools/c-analyzer/cpython/_parser.py.
382-
383-
If the tool otherwise reports an unsupported global variable
384-
then first try to make it non-global, possibly adding to
385-
PyInterpreterState (for core code) or module state (for
386-
extension modules). In an emergency, you can add the
387-
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
388-
to get CI passing, but doing so should be avoided. If
389-
this course it taken, be sure to create an issue for
390-
eliminating the global (and CC ericsnowcurrently).
391-
'''))
398+
print(EXPLANATION)
392399
sys.exit(len(failed))
393400

394401

0 commit comments

Comments
 (0)
0