[Tool: c-analyzer] Print Helpful Error Messages for Invalid .tsv Files
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em Tools/c-analyzer e inspecione como check-c-globals.py lê Tools/c-analyzer/cpython/ignored.tsv e globals-to-fix.tsv. Execute ./python Tools/c-analyzer/check-c-globals.py --format summary com exemplos de TSV malformados. Está concluído quando a ferramenta relata erros específicos para espaços no lugar de tabulações, espaços próximos a tabulações e linhas incompletas.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- tooling
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100