Skip to content

Commit 9c658d3

Browse files
Merge pull request #3594 from raspberrypi/lxml-update
Update lxml version and fix some syntax warnings
2 parents 2090b95 + 4938f37 commit 9c658d3

File tree

7 files changed

+60
-42
lines changed

7 files changed

+60
-42
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ jobs:
4040
uses: carlosperate/arm-none-eabi-gcc-action@v1.8.1
4141
- name: Install Doxygen
4242
run: |
43-
wget https://www.doxygen.nl/files/doxygen-1.9.6.linux.bin.tar.gz
44-
tar xf doxygen-1.9.6.linux.bin.tar.gz -C "$HOME"
45-
echo "$HOME/doxygen-1.9.6/bin" >> $GITHUB_PATH
43+
wget https://www.doxygen.nl/files/doxygen-1.10.0.linux.bin.tar.gz
44+
tar xf doxygen-1.10.0.linux.bin.tar.gz -C "$HOME"
45+
echo "$HOME/doxygen-1.10.0/bin" >> $GITHUB_PATH
4646
- name: Build Doxygen documentation
4747
run: make build_doxygen_adoc
4848
- name: Build documentation
4949
run: make -j 2
50+
- name: Run tests
51+
run: ./tests/run_documentation_tests.sh
5052
- name: Deploy to Mythic Beasts
5153
if: ${{ github.ref == 'refs/heads/master' }}
5254
uses: ./.github/actions/deploy-action

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pyyaml == 6.0.1
2-
lxml == 4.9.3
2+
lxml

scripts/create_build_adoc_doxygen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
def check_no_markdown(filename):
1111
with open(filename) as fh:
1212
asciidoc = fh.read()
13-
if re.search('```\n.*?\n```', asciidoc):
13+
if re.search(r'```\n.*?\n```', asciidoc):
1414
raise Exception("{} uses triple-backticks for markup - please use four-hyphens instead".format(filename))
1515
# strip out code blocks
16-
asciidoc = re.sub('----\n.*?\n----', '', asciidoc, flags=re.DOTALL)
16+
asciidoc = re.sub(r'----\n.*?\n----', '', asciidoc, flags=re.DOTALL)
1717
# strip out pass-through blocks
18-
asciidoc = re.sub('\+\+\+\+\n.*?\n\+\+\+\+', '', asciidoc, flags=re.DOTALL)
19-
if re.search('(?:^|\n)#+', asciidoc):
18+
asciidoc = re.sub(r'\+\+\+\+\n.*?\n\+\+\+\+', '', asciidoc, flags=re.DOTALL)
19+
if re.search(r'(?:^|\n)#+', asciidoc):
2020
raise Exception("{} contains a Markdown-style header (i.e. '#' rather than '=')".format(filename))
2121
if re.search(r'(\[.+?\]\(.+?\))', asciidoc):
2222
raise Exception("{} contains a Markdown-style link (i.e. '[title](url)' rather than 'url[title]')".format(filename))
@@ -67,7 +67,7 @@ def check_no_markdown(filename):
6767
if not seen_header:
6868
seen_header = True
6969
else:
70-
m = re.match('^(include::)(.+)(\[\]\n?)$', line)
70+
m = re.match(r'^(include::)(.+)(\[\]\n?)$', line)
7171
if m:
7272
line = m.group(1) + os.path.join('{includedir}/{parentdir}', m.group(2)) + m.group(3)
7373
new_contents += line

scripts/create_output_supplemental_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_release_version(doxyfile_path):
99
version = "unknown"
1010
with open(doxyfile_path) as f:
1111
doxy_content = f.read()
12-
version_search = re.search("(\nPROJECT_NUMBER\s*=\s*)([\d.]+)", doxy_content)
12+
version_search = re.search(r"(\nPROJECT_NUMBER\s*=\s*)([\d.]+)", doxy_content)
1313
if version_search is not None:
1414
version = version_search.group(2)
1515
return version

scripts/tests/test_doxygen_adoc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ def test_doxygen_adoc_variables(self):
4040
# test will fail if ANY of the below are different or missing
4141
expected = {
4242
"pico-sdk/index_doxygen.adoc" : [
43-
":doctitle: Raspberry Pi Documentation - Introduction",
43+
":doctitle: Introduction - Raspberry Pi Documentation",
4444
":page-sub_title: Introduction"
4545
],
4646
"pico-sdk/hardware.adoc": [
47-
":doctitle: Raspberry Pi Documentation - Hardware APIs",
47+
":doctitle: Hardware APIs - Raspberry Pi Documentation",
4848
":page-sub_title: Hardware APIs"
4949
],
5050
"pico-sdk/high_level.adoc": [
51-
":doctitle: Raspberry Pi Documentation - High Level APIs",
51+
":doctitle: High Level APIs - Raspberry Pi Documentation",
5252
":page-sub_title: High Level APIs"
5353
],
5454
"pico-sdk/third_party.adoc": [
55-
":doctitle: Raspberry Pi Documentation - Third-party Libraries",
55+
":doctitle: Third-party Libraries - Raspberry Pi Documentation",
5656
":page-sub_title: Third-party Libraries"
5757
],
5858
"pico-sdk/networking.adoc": [
59-
":doctitle: Raspberry Pi Documentation - Networking Libraries",
59+
":doctitle: Networking Libraries - Raspberry Pi Documentation",
6060
":page-sub_title: Networking Libraries"
6161
],
6262
"pico-sdk/runtime.adoc": [
63-
":doctitle: Raspberry Pi Documentation - Runtime Infrastructure",
63+
":doctitle: Runtime Infrastructure - Raspberry Pi Documentation",
6464
":page-sub_title: Runtime Infrastructure"
6565
],
6666
"pico-sdk/misc.adoc": [
67-
":doctitle: Raspberry Pi Documentation - External API Headers",
67+
":doctitle: External API Headers - Raspberry Pi Documentation",
6868
":page-sub_title: External API Headers"
6969
]
7070
}

scripts/transform_doxygen_html.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
# TO DO:
1515
# do internal href links need to be updated?
1616

17+
def add_next_with_tail(target, inserted):
18+
if target.tail is not None:
19+
inserted.tail = inserted.tail + target.tail if inserted.tail is not None else target.tail
20+
target.tail = None
21+
target.addnext(inserted)
22+
1723
def get_all_text(node):
1824
text = node.text if node.text else None
1925
if text:
@@ -69,7 +75,7 @@ def make_attribute_selector(sel, item):
6975
if "*" in att_value:
7076
contains = True
7177
if contains == True:
72-
val = re.sub("\*", "", " ".join(att["value"]))
78+
val = re.sub(r"\*", "", " ".join(att["value"]))
7379
atts.append("contains(@" + att["name"] + ",'" + val + "')")
7480
else:
7581
# otherwise it's a normal attribute selector
@@ -200,16 +206,16 @@ def transform_element(item, root, is_child=False):
200206
# set attributes, add text/tail, and add children
201207
new_tree = add_content_to_tree(new_tree, match)
202208
# add the new tree to the document
203-
match.addnext(new_tree)
209+
add_next_with_tail(match, new_tree)
204210
# remove the old element
205211
match.getparent().remove(match)
206212
else:
207213
# if there is no tree, the element should be removed
208214
# first, preserve any children:
209215
for child in reversed(match.findall("./*")):
210-
match.addnext(child)
216+
add_next_with_tail(match, child)
211217
# handle the tail if needed
212-
if match.tail is not None and re.search("\S", match.tail) is not None:
218+
if match.tail is not None and re.search(r"\S", match.tail) is not None:
213219
prev = match.getprevious()
214220
if prev is not None:
215221
prev.tail = prev.tail + match.tail if prev.tail is not None else match.tail
@@ -309,7 +315,7 @@ def find_item_in_toc(h_json, filename):
309315

310316
def fix_external_links(adoc, h_json):
311317
try:
312-
matches = re.findall("(href=[\"'])([^\s>]*?)([\"'])", adoc)
318+
matches = re.findall(r"(href=[\"'])([^\s>]*?)([\"'])", adoc)
313319
for match in matches:
314320
href = match[1]
315321
# href = match.get("href")
@@ -452,7 +458,7 @@ def retag_heading(head, headtype):
452458
else:
453459
newel.set("id", head.get("id"))
454460
newel.text = text
455-
head.addnext(newel)
461+
add_next_with_tail(head, newel)
456462
head.getparent().remove(head)
457463
except Exception as e:
458464
exc_type, exc_obj, exc_tb = sys.exc_info()
@@ -475,11 +481,11 @@ def prep_for_adoc(root):
475481
def make_adoc(root_string, title_text, filename):
476482
try:
477483
my_id = make_filename_id(filename)
478-
root_string = re.sub("<\/div>\s*?$", "", root_string, flags=re.S)
479-
root_string = re.sub('<div class="contents" id="\S*?">', "", root_string)
484+
root_string = re.sub(r"<\/div>\s*?$", "", root_string, flags=re.S)
485+
root_string = re.sub(r'<div class="contents" id="\S*?">', "", root_string)
480486
root_string = "[["+my_id+"]]\n== " + title_text + "\n\n++++\n" + root_string
481-
root_string = re.sub('(<p[^>]+class="adoc-h2"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n[[\\2]]\n=== \\4\n\n++++\n', root_string, flags=re.S)
482-
root_string = re.sub('(<p[^>]+class="adoc-h3"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n[[\\2]]\n==== \\4\n\n++++\n', root_string, flags=re.S)
487+
root_string = re.sub(r'(<p[^>]+class="adoc-h2"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n[[\\2]]\n=== \\4\n\n++++\n', root_string, flags=re.S)
488+
root_string = re.sub(r'(<p[^>]+class="adoc-h3"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n[[\\2]]\n==== \\4\n\n++++\n', root_string, flags=re.S)
483489
root_string = root_string + "\n++++\n"
484490
except Exception as e:
485491
exc_type, exc_obj, exc_tb = sys.exc_info()
@@ -488,7 +494,7 @@ def make_adoc(root_string, title_text, filename):
488494

489495
def decrease_heading_levels(adoc):
490496
try:
491-
adoc = re.sub("\n==", "\n=", adoc, flags=re.S)
497+
adoc = re.sub(r"\n==", "\n=", adoc, flags=re.S)
492498
except Exception as e:
493499
exc_type, exc_obj, exc_tb = sys.exc_info()
494500
print("ERROR: ", e, exc_tb.tb_lineno)
@@ -521,29 +527,29 @@ def parse_header(header_path):
521527
try:
522528
with open(header_path) as h:
523529
content = h.read()
524-
blocks = re.findall("^(\s*)(\*|\/\*\*)(\s*)(\s)(\*)(\s)(\\\\)(defgroup)([^}]*)(\@\})", content, re.M)
530+
blocks = re.findall(r"^(\s*)(\*|\/\*\*)(\s*)(\s)(\*)(\s)(\\)(defgroup)([^}]*)(\@\})", content, re.M)
525531
for (a, b, c, d, e, f, g, h, i, j) in blocks:
526-
items = i.split("\defgroup")
532+
items = i.split(r"\defgroup")
527533
group_id = None
528534
for item in items:
529535
if group_id is None: # must be the first item in the list
530-
m = re.match("(\s*)(\S*)(\s*)([^*]*)(.*?)(@\{)", item, re.S)
536+
m = re.match(r"(\s*)(\S*)(\s*)([^*]*)(.*?)(@\{)", item, re.S)
531537
group_id = m.group(2)
532538
group_filename = "group_"+group_id+".html"
533539
group_filename = re.sub("_", "__", group_filename)
534540
group_name = m.group(4)
535-
group_name = re.sub("\s*$", "", group_name, re.M)
541+
group_name = re.sub(r"\s*$", "", group_name, re.M)
536542
group_desc = m.group(5)
537-
group_desc = re.sub("\n", "", group_desc, re.M)
538-
group_desc = re.sub("\*", "", group_desc, re.M)
539-
group_desc = re.sub("^\s", "", group_desc, re.M)
543+
group_desc = re.sub(r"\n", "", group_desc, re.M)
544+
group_desc = re.sub(r"\*", "", group_desc, re.M)
545+
group_desc = re.sub(r"^\s", "", group_desc, re.M)
540546
group_json = { 'group_id': group_id, 'name': group_name, 'description': group_desc, 'html': group_filename, 'subitems': [] }
541547
h_json.append(group_json)
542548
else:
543549
cleaned = item
544-
cleaned = re.sub("\n*", "", cleaned, re.M)
545-
cleaned = re.sub("^\s*", "", cleaned, re.M)
546-
cleaned = re.sub("\s*\*\s*$", "", cleaned, re.M)
550+
cleaned = re.sub(r"\n*", "", cleaned, re.M)
551+
cleaned = re.sub(r"^\s*", "", cleaned, re.M)
552+
cleaned = re.sub(r"\s*\*\s*$", "", cleaned, re.M)
547553
val = cleaned.split(" ")[0]
548554
filename = re.sub("_", "__", val)
549555
filename = "group__" + filename
@@ -705,12 +711,12 @@ def parse_individual_file(html_path, html_file, complete_json_mappings, updated_
705711
# read the input root
706712
with open(this_path) as h:
707713
html_content = h.read()
708-
html_content = re.sub('<\!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1\.0 Transitional\/\/EN" "https:\/\/www\.w3\.org\/TR\/xhtml1\/DTD\/xhtml1-transitional\.dtd">', '', html_content)
714+
html_content = re.sub(r'<\!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1\.0 Transitional\/\/EN" "https:\/\/www\.w3\.org\/TR\/xhtml1\/DTD\/xhtml1-transitional\.dtd">', '', html_content)
709715
html_content = re.sub('rel="stylesheet">', 'rel="stylesheet"/>', html_content)
710716
html_content = re.sub('&display=swap"', '"', html_content)
711-
html_content = re.sub('<img src="logo-mobile\.svg" alt="Raspberry Pi">', '', html_content)
712-
html_content = re.sub('<img src="logo\.svg" alt="Raspberry Pi">', '', html_content)
713-
html_content = re.sub("<\!-- HTML header for doxygen \S*?-->", '', html_content)
717+
html_content = re.sub(r'<img src="logo-mobile\.svg" alt="Raspberry Pi">', '', html_content)
718+
html_content = re.sub(r'<img src="logo\.svg" alt="Raspberry Pi">', '', html_content)
719+
html_content = re.sub(r"<\!-- HTML header for doxygen \S*?-->", '', html_content)
714720
html_content = re.sub(' xmlns="http://www.w3.org/1999/xhtml"', '', html_content)
715721
root = etree.HTML(html_content)
716722

tests/run_documentation_tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/bash
2+
3+
# run from the top level: ./tests/run_documentation_tests.sh
4+
5+
python3 -m unittest tests.test_create_build_adoc_doxygen
6+
python3 -m unittest tests.test_create_build_adoc_include
7+
python3 -m unittest tests.test_create_build_adoc
8+
python3 -m unittest tests.test_create_nav
9+
cd scripts/
10+
python3 -m unittest tests.test_doxygen_adoc

0 commit comments

Comments
 (0)