diff --git a/docs/build.py b/docs/build.py index d99c88e7c..cfd75eb26 100755 --- a/docs/build.py +++ b/docs/build.py @@ -66,12 +66,18 @@ if len(args) >= 1: develop = True -def cmd(s): +def cmd(s, start_dir=None): + if start_dir is None: + start_dir = os.getcwd() + + saved_dir = os.getcwd() + os.chdir(start_dir) print("") print(s) print("-------------------------------------") - result = os.system(s) + os.chdir(saved_dir) + if result != 0: print("Exit build due to previous error") sys.exit(result) @@ -80,7 +86,7 @@ def cmd(s): # Get the current branch name status, br = subprocess.getstatusoutput("git branch --show-current") _, gitcommit = subprocess.getstatusoutput("git rev-parse HEAD") -br = re.sub('\* ', '', br) +br = re.sub(r'\* ', '', br) urlpath = re.sub('release/', '', br) @@ -141,10 +147,12 @@ print("Add translation") add_translation.exec(temp_directory) print("Running doxygen") -cmd('cd "{temp_directory}" && doxygen Doxyfile'.format(temp_directory=temp_directory)) +cmd('doxygen Doxyfile', temp_directory) print('Reading Doxygen output') +doc_builder.EMIT_WARNINGS = False + doc_builder.run( project_path, temp_directory, @@ -205,11 +213,23 @@ else: f.write(index_data.encode('utf-8')) # BUILD HTML - - +# This version of get_version() works correctly under Windows and Linux. +# Credit: @kdschlosser def get_version(): - _, ver = subprocess.getstatusoutput("../scripts/find_version.sh") - return ver + path = os.path.join(project_path, 'lv_version.h') + with open(path, 'rb') as fle: + d = fle.read().decode('utf-8') + + d = d.split('#define LVGL_VERSION_MAJOR', 1)[-1] + major, d = d.split('\n', 1) + d = d.split('#define LVGL_VERSION_MINOR', 1)[-1] + minor, d = d.split('\n', 1) + + # d = d.split('#define LVGL_VERSION_PATCH', 1)[-1] + # patch, d = d.split('\n', 1) + + return f'{major.strip()}.{minor.strip()}' + cmd('sphinx-build -b html "{src}" "{dst}" -D version="{version}" -E -j {cpu}'.format( src=html_src_path, diff --git a/docs/doc_builder.py b/docs/doc_builder.py index fca486c2f..bbf5a3e1d 100644 --- a/docs/doc_builder.py +++ b/docs/doc_builder.py @@ -1134,6 +1134,11 @@ def iter_src(n, p): def clean_name(nme): + # Handle error: + # AttributeError: 'NoneType' object has no attribute 'startswith' + if nme is None: + return nme + if nme.startswith('_lv_'): nme = nme[4:] elif nme.startswith('lv_'): @@ -1146,6 +1151,11 @@ def clean_name(nme): def is_name_match(item_name, obj_name): + # Handle error: + # AttributeError: 'NoneType' object has no attribute 'split' + if obj_name is None: + return False + u_num = item_name.count('_') + 1 obj_name = obj_name.split('_') @@ -1207,7 +1217,7 @@ class XMLSearch(object): status, br = subprocess.getstatusoutput("git branch") _, gitcommit = subprocess.getstatusoutput("git rev-parse HEAD") - br = re.sub('\* ', '', br) + br = re.sub(r'\* ', '', br) urlpath = re.sub('release/', '', br) @@ -1292,6 +1302,7 @@ def run(project_path, temp_directory, *doc_paths): if not os.path.exists(api_path): os.makedirs(api_path) + # Generate .RST files for API pages. iter_src('API', '') index = load_xml('index')