Help needed with codeformat - prepocessing errors #18404
-
|
Im working on a PR to support metaclasses that needs quite some changes to @Josverl ➜ /workspaces/micropython (feat/metaclass) $ ./tools/codeformat.py py/modbuiltins.c
Traceback (most recent call last):
File "/workspaces/micropython/./tools/codeformat.py", line 200, in <module>
main()
File "/workspaces/micropython/./tools/codeformat.py", line 186, in main
fixup_c(file)
File "/workspaces/micropython/./tools/codeformat.py", line 119, in fixup_c
raise IndentationError(
IndentationError: dedent stack is empty for "endif" at py/modbuiltins.c:54Note the same error also happens in CI in the Code formatting workflow. Note that It has been somewhat frustrating to see my work deleted by a pre-commit hook every time I try to check something in ..... So please help me sanity check ; so I can finally check in my code . Questions:
for config and code see : https://gist.github.com/Josverl/505bcfb547f321d4e5c8b15c9cf4472c#file-modbuiltins-c |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
It doesn't like this part: https://gist.github.com/Josverl/505bcfb547f321d4e5c8b15c9cf4472c#file-modbuiltins-c-L49-L54 #if MICROPY_METACLASS || MICROPY_INIT_SUBCLASS
// Keyword arguments may include 'metaclass'
static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
#else
static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) {
#endifSpecifically, what it doesn't like is that two indenting rules clash: It tries to keep the The way to write it instead would be: #if MICROPY_METACLASS || MICROPY_INIT_SUBCLASS
// Keyword arguments may include 'metaclass'
static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args)
#else
static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
#endif
{Aka moving the curly brace outside of the preprocessor block. EDIT: I came across it before and then improve the error message, which previously was even less helpful, in #17837.
That's indeed not great. In addition to more helpful errors, there should probably be a try-catch around the entire logic, and if any exception is raised it should revert the file to it's original state. Or, since at that point we're caching the entire file in memory anyway, simpler would be to write the reformatted code to a variable first and only write it back to the filesystem when everything completed without errors. |
Beta Was this translation helpful? Give feedback.
It doesn't like this part:
https://gist.github.com/Josverl/505bcfb547f321d4e5c8b15c9cf4472c#file-modbuiltins-c-L49-L54
Specifically, what it doesn't like is that two indenting rules clash: It tries to keep the
#if,#elseand#endifon the same indentation level. But at the same time, the#elseand#endifare inside the block and should have the same indentation as the rest of the block.The way to write it…