all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
This commit is contained in:
@@ -13,10 +13,7 @@ import os
|
||||
import argparse
|
||||
|
||||
|
||||
pattern = re.compile(
|
||||
r"[\n;]\s*MP_REGISTER_MODULE\((.*?),\s*(.*?),\s*(.*?)\);",
|
||||
flags=re.DOTALL
|
||||
)
|
||||
pattern = re.compile(r"[\n;]\s*MP_REGISTER_MODULE\((.*?),\s*(.*?),\s*(.*?)\);", flags=re.DOTALL)
|
||||
|
||||
|
||||
def find_c_file(obj_file, vpath):
|
||||
@@ -28,7 +25,7 @@ def find_c_file(obj_file, vpath):
|
||||
"""
|
||||
c_file = None
|
||||
relative_c_file = os.path.splitext(obj_file)[0] + ".c"
|
||||
relative_c_file = relative_c_file.lstrip('/\\')
|
||||
relative_c_file = relative_c_file.lstrip("/\\")
|
||||
for p in vpath:
|
||||
possible_c_file = os.path.join(p, relative_c_file)
|
||||
if os.path.exists(possible_c_file):
|
||||
@@ -50,7 +47,7 @@ def find_module_registrations(c_file):
|
||||
# No c file to match the object file, skip
|
||||
return set()
|
||||
|
||||
with io.open(c_file, encoding='utf-8') as c_file_obj:
|
||||
with io.open(c_file, encoding="utf-8") as c_file_obj:
|
||||
return set(re.findall(pattern, c_file_obj.read()))
|
||||
|
||||
|
||||
@@ -67,15 +64,20 @@ def generate_module_table_header(modules):
|
||||
for module_name, obj_module, enabled_define in modules:
|
||||
mod_def = "MODULE_DEF_{}".format(module_name.upper())
|
||||
mod_defs.append(mod_def)
|
||||
print((
|
||||
"#if ({enabled_define})\n"
|
||||
" extern const struct _mp_obj_module_t {obj_module};\n"
|
||||
" #define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n"
|
||||
"#else\n"
|
||||
" #define {mod_def}\n"
|
||||
"#endif\n"
|
||||
).format(module_name=module_name, obj_module=obj_module,
|
||||
enabled_define=enabled_define, mod_def=mod_def)
|
||||
print(
|
||||
(
|
||||
"#if ({enabled_define})\n"
|
||||
" extern const struct _mp_obj_module_t {obj_module};\n"
|
||||
" #define {mod_def} {{ MP_ROM_QSTR({module_name}), MP_ROM_PTR(&{obj_module}) }},\n"
|
||||
"#else\n"
|
||||
" #define {mod_def}\n"
|
||||
"#endif\n"
|
||||
).format(
|
||||
module_name=module_name,
|
||||
obj_module=obj_module,
|
||||
enabled_define=enabled_define,
|
||||
mod_def=mod_def,
|
||||
)
|
||||
)
|
||||
|
||||
print("\n#define MICROPY_REGISTERED_MODULES \\")
|
||||
@@ -88,13 +90,13 @@ def generate_module_table_header(modules):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--vpath", default=".",
|
||||
help="comma separated list of folders to search for c files in")
|
||||
parser.add_argument("files", nargs="*",
|
||||
help="list of c files to search")
|
||||
parser.add_argument(
|
||||
"--vpath", default=".", help="comma separated list of folders to search for c files in"
|
||||
)
|
||||
parser.add_argument("files", nargs="*", help="list of c files to search")
|
||||
args = parser.parse_args()
|
||||
|
||||
vpath = [p.strip() for p in args.vpath.split(',')]
|
||||
vpath = [p.strip() for p in args.vpath.split(",")]
|
||||
|
||||
modules = set()
|
||||
for obj_file in args.files:
|
||||
@@ -104,5 +106,5 @@ def main():
|
||||
generate_module_table_header(sorted(modules))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user