LVGL binding update for python 3.12 (#21076)

This commit is contained in:
s-hadinger 2024-03-31 22:08:27 +02:00 committed by GitHub
parent 9f4c994034
commit 76b1f48f0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 36 deletions

View File

@ -233,12 +233,12 @@ class type_mapper_class:
# Group 1: 'void'
# Group 2: 'lv_obj_set_parent'
# Group 3: 'lv_obj_t * obj, lv_obj_t * parent'
parse_func_regex = re.compile("(.*?)\s(\w+)\((.*?)\)")
parse_func_regex = re.compile(r"(.*?)\s(\w+)\((.*?)\)")
# parse call argument type
# Ex: 'const lv_obj_t * parent' -> 'const ', 'lv_obj_t', ' * ', 'parent'
# Ex: 'bool auto_fit' -> '', 'bool', ' ', 'auto_fit'
parse_arg_regex = re.compile("(\w+\s+)?(\w+)([\*\s]+)(\w+)(\[\])?")
parse_arg_regex = re.compile(r"(\w+\s+)?(\w+)([\*\s]+)(\w+)(\[\])?")
# the following types are skipped without warning, because it would be too complex to adapt (so we don't map any function using or returning these types)
skipping_type = [
@ -508,16 +508,16 @@ class type_mapper_class:
print(f"# mapping not used '{k}'", file=sys.stderr)
def clean_c_line(self, l_raw):
l_raw = re.sub('//.*$', '', l_raw) # remove trailing comments
l_raw = re.sub('LV_ATTRIBUTE_FAST_MEM ', '', l_raw) # remove LV_ATTRIBUTE_FAST_MEM marker
l_raw = re.sub('\s+', ' ', l_raw) # replace any multi-space with a single space
l_raw = re.sub(r'//.*$', '', l_raw) # remove trailing comments
l_raw = re.sub(r'LV_ATTRIBUTE_FAST_MEM ', '', l_raw) # remove LV_ATTRIBUTE_FAST_MEM marker
l_raw = re.sub(r'\s+', ' ', l_raw) # replace any multi-space with a single space
l_raw = l_raw.strip(" \t\n\r") # remove leading or trailing spaces
l_raw = re.sub('static ', '', l_raw) # remove `static` qualifier
l_raw = re.sub('inline ', '', l_raw) # remove `inline` qualifier
l_raw = re.sub('const\s+char\s*\*', 'constchar *', l_raw)
l_raw = re.sub('^char\s*\*', 'retchar *', l_raw) # special case for returning a char*
l_raw = re.sub('const ', '', l_raw)
l_raw = re.sub('struct ', '', l_raw)
l_raw = re.sub(r'static ', '', l_raw) # remove `static` qualifier
l_raw = re.sub(r'inline ', '', l_raw) # remove `inline` qualifier
l_raw = re.sub(r'const\s+char\s*\*', 'constchar *', l_raw)
l_raw = re.sub(r'^char\s*\*', 'retchar *', l_raw) # special case for returning a char*
l_raw = re.sub(r'const ', '', l_raw)
l_raw = re.sub(r'struct ', '', l_raw)
return l_raw
def parse_c_line(self, l_raw):
@ -688,9 +688,9 @@ with open(lv_module_file) as f:
l_raw = l_raw.strip(" \t\n\r") # remove leading or trailing spaces
if l_raw.startswith("//"):
lv_module.append( [ None, l_raw ] ) # if key in None then add comment line
l_raw = re.sub('//.*$', '', l_raw) # remove trailing comments
l_raw = re.sub('\s+', '', l_raw) # remove all spaces
l_raw = re.sub(',.*$', '', l_raw) # remove comma and anything after it
l_raw = re.sub(r'//.*$', '', l_raw) # remove trailing comments
l_raw = re.sub(r'\s+', '', l_raw) # remove all spaces
l_raw = re.sub(r',.*$', '', l_raw) # remove comma and anything after it
if (len(l_raw) == 0): continue
k_v = l_raw.split("=")

View File

@ -26,22 +26,22 @@ def list_files(prefix, glob_list):
def clean_source(raw):
raw = comment_remover(raw) # remove comments
# convert cr/lf or cr to lf
raw = re.sub('\r\n ', '\n', raw)
raw = re.sub('\r', '\n', raw)
raw = re.sub(r'\r\n ', '\n', raw)
raw = re.sub(r'\r', '\n', raw)
# group multilines into a single line, i.e. if line ends with '\', put in a single line
raw = re.sub('\\\\\n', ' ', raw)
raw = re.sub(r'\\\n', ' ', raw)
# remove preprocessor directives
raw = re.sub('\n[ \t]*#[^\n]*(?=\n)', '', raw)
raw = re.sub('^[ \t]*#[^\n]*\n', '', raw)
raw = re.sub('\n[ \t]*#[^\n]*$', '', raw)
raw = re.sub(r'\n[ \t]*#[^\n]*(?=\n)', '', raw)
raw = re.sub(r'^[ \t]*#[^\n]*\n', '', raw)
raw = re.sub(r'\n[ \t]*#[^\n]*$', '', raw)
# remove extern "C" {}
raw = re.sub('extern\s+"C"\s+{(.*)}', '\\1', raw, flags=re.DOTALL)
raw = re.sub(r'extern\s+"C"\s+{(.*)}', '\\1', raw, flags=re.DOTALL)
# remove empty lines
raw = re.sub('\n[ \t]*(?=\n)', '', raw)
raw = re.sub('^[ \t]*\n', '', raw) # remove first empty line
raw = re.sub('\n[ \t]*$', '', raw) # remove last empty line
raw = re.sub(r'\n[ \t]*(?=\n)', '', raw)
raw = re.sub(r'^[ \t]*\n', '', raw) # remove first empty line
raw = re.sub(r'\n[ \t]*$', '', raw) # remove last empty line
return raw
# ################################################################################
@ -115,29 +115,29 @@ for header_name in headers_names:
# remove anything in '{' '}'
while True:
(raw, repl) = re.subn('\{[^{]*?\}', ';', raw, flags=re.DOTALL) # replace with ';' to make pattern matching still work
(raw, repl) = re.subn(r'\{[^{]*?\}', ';', raw, flags=re.DOTALL) # replace with ';' to make pattern matching still work
if (repl == 0): break # no more replace, stop
raw_f = re.findall('(^|;|})\s*([^;{}]+\(.*?\))\s*(?=(;|{))', raw, flags=re.DOTALL)
raw_f = re.findall(r'(^|;|})\s*([^;{}]+\(.*?\))\s*(?=(;|{))', raw, flags=re.DOTALL)
fun_defs = [ x[1] for x in raw_f]
# remove any CRLF or multi-space
fun_defs = [ re.sub('[ \t\r\n]+', ' ', x) for x in fun_defs]
fun_defs = [ re.sub(r'[ \t\r\n]+', ' ', x) for x in fun_defs]
# parse individual
for fun in fun_defs:
# remove LV_ATTRIBUTE_FAST_MEM
fun = re.sub('LV_ATTRIBUTE_FAST_MEM ', '', fun)
fun = re.sub(r'LV_ATTRIBUTE_FAST_MEM ', '', fun)
# remove LV_ATTRIBUTE_TIMER_HANDLER
fun = re.sub('LV_ATTRIBUTE_TIMER_HANDLER ', '', fun)
fun = re.sub(r'LV_ATTRIBUTE_TIMER_HANDLER ', '', fun)
# remove extern
fun = re.sub('extern ', '', fun)
fun = re.sub(r'extern ', '', fun)
exclude = False
for exclude_prefix in ["typedef", "_LV_", "LV_"]:
if fun.startswith(exclude_prefix): exclude = True
if exclude: continue
# extrac the function name
fun_name = re.search('\s(\w+)\([^\(]*$', fun)
fun_name = re.search(r'\s(\w+)\([^\(]*$', fun)
if fun_name != None:
fun_name = fun_name.group(1) # we now have the function name
@ -359,21 +359,21 @@ for header_name in headers_names:
print(f"// File: {header_name}")
# extract enums
enums = re.findall('enum\s+\w*\s*{(.*?)}', raw, flags=re.DOTALL)
enums = re.findall(r'enum\s+\w*\s*{(.*?)}', raw, flags=re.DOTALL)
for enum in enums: # iterate on all matches
# exclude LV_PROPERTY_ID
# we compile with `#define LV_USE_OBJ_PROPERTY 0`
# and remove all instances of `LV_PROPERTY_ID(OBJ, FLAG_START, LV_PROPERTY_TYPE_INT, 0),`
if re.search('LV_PROPERTY_ID', enum): continue
# remove enums defined via a macro
enum = re.sub('\S+\((.*?),.*?\),', '\\1,', enum) # turn 'LV_STYLE_PROP_INIT(LV_STYLE_SIZE, 0x0, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),' into 'LV_STYLE_SIZE'
enum = re.sub(r'\S+\((.*?),.*?\),', '\\1,', enum) # turn 'LV_STYLE_PROP_INIT(LV_STYLE_SIZE, 0x0, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),' into 'LV_STYLE_SIZE'
#
enum_elt = enum.split(",")
for enum_item in enum_elt:
# remove any space
enum_item = re.sub('[ \t\n]', '', enum_item)
enum_item = re.sub(r'[ \t\n]', '', enum_item)
# remove anything after '='
enum_item = re.sub('=.*$', '', enum_item)
enum_item = re.sub(r'=.*$', '', enum_item)
# item is ready
exclude = False
@ -387,7 +387,7 @@ for header_name in headers_names:
print(enum_item)
# extract `LV_EXPORT_CONST_INT()` int constants
constints = re.findall('LV_EXPORT_CONST_INT\((\w+)\)', raw, flags=re.DOTALL)
constints = re.findall(r'LV_EXPORT_CONST_INT\((\w+)\)', raw, flags=re.DOTALL)
for constint in constints:
print(constint)
sys.stdout.close()