summaryrefslogtreecommitdiffstatshomepage
path: root/py/makemoduledefs.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-27 15:36:53 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-28 10:33:03 +1100
commit69661f3343bedf86e514337cff63d96cc42f8859 (patch)
treeaf5dfb380ffdb75dda84828f63cf9d840d992f0f /py/makemoduledefs.py
parent3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff)
downloadmicropython-69661f3343bedf86e514337cff63d96cc42f8859.tar.gz
micropython-69661f3343bedf86e514337cff63d96cc42f8859.zip
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'py/makemoduledefs.py')
-rw-r--r--py/makemoduledefs.py44
1 files changed, 23 insertions, 21 deletions
diff --git a/py/makemoduledefs.py b/py/makemoduledefs.py
index f17b0e38df..d718da6e02 100644
--- a/py/makemoduledefs.py
+++ b/py/makemoduledefs.py
@@ -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()