[Tool: c-analyzer] Print Helpful Error Messages for Invalid .tsv Files
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Feature or enhancement
CI uses the c-analyzer tool (Tools/c-analyzer) to make sure we don't add any new unsupported C global variables to the code base. The tool makes use of .tsv files (tab-separated values) for some customization. The most import of these files are Tools/c-analyzer/cpython/ignored.tsv and .../globals-to-fix.tsv. If someone adds a line that has spaces instead of tabs (or spaces around the tabs), which is easy to do, then the tool unhelpfully fails as though the line weren't there.
(expand for an example)
From the CI check in gh-116413:
python3.12 ./Tools/c-analyzer/check-c-globals.py \
--format summary \
--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ....
checking analysis results...
[extraneous text snipped]
Non-constant global variables are generally not supported
in the CPython repo. We use a tool to analyze the C code
and report if any unsupported globals are found. The tool
may be run manually with:
./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]
Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).
If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code. If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.
If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules). In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided. If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).
[extraneous text snipped]
make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.
There's a similar situation when someone adds a line but forgets one of the row values, likely the last one which is usually a single hyphen. Such a line gets ignored without any indication to the user what went wrong or what to do about it.
(expand for an example)
From the CI check in gh-116413:
python3.12 ./Tools/c-analyzer/check-c-globals.py \
--format summary \
--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ....
checking analysis results...
[extraneous text snipped]
Non-constant global variables are generally not supported
in the CPython repo. We use a tool to analyze the C code
and report if any unsupported globals are found. The tool
may be run manually with:
./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]
Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).
If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code. If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.
If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules). In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided. If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).
make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8280034808/job/22655683079#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.
It would be helpful if the tool failed with an appropriate specific message for the following cases:
- spaces instead of tabs
- spaces next to tabs
- incomplete lines
CC @iritkatriel
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans Tools/c-analyzer et examinez comment check-c-globals.py lit Tools/c-analyzer/cpython/ignored.tsv et globals-to-fix.tsv. Exécutez ./python Tools/c-analyzer/check-c-globals.py --format summary avec des exemples de TSV malformés. C’est terminé lorsque l’outil signale des erreurs spécifiques pour les espaces à la place des tabulations, les espaces à côté des tabulations et les lignes incomplètes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100