Skip to content

Commit

Permalink
[qr] support drake tags
Browse files Browse the repository at this point in the history
  • Loading branch information
vacancy committed Sep 4, 2023
1 parent 6fa11fd commit 0400f1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lisdf/parsing/xml_j/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ def _inner(node: XMLNode):
def check_done(node: XMLNode, attr: bool = True, children: bool = True) -> None:
"""A helper function to check whether all attributes and children of a
node have been processed."""

for attr in node.attributes:
if attr.startswith('gazebo') or attr.startswith('drake'):
# remove the attribute
node.attributes.pop(attr)
for child in node.children:
if child.tag.startswith('gazebo') or child.tag.startswith('drake'):
# remove the child
node.children.remove(child)

if attr:
if len(node.attributes) != 0:
print("Unprocessed attributes.")
Expand Down
9 changes: 4 additions & 5 deletions lisdf/parsing/xml_j/xml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import xml.etree.ElementTree as et
from lxml import etree as et

Check failure on line 1 in lisdf/parsing/xml_j/xml.py

View workflow job for this annotation

GitHub Actions / autoformat (3.8)

Imports are incorrectly sorted and/or formatted.
from typing import Any, List, Optional

from lisdf.utils.printing import indent_text
Expand Down Expand Up @@ -133,9 +132,9 @@ def _xml2obj(element) -> XMLNode:


def load_string(value: str) -> XMLNode:
# TODO:: temporary fix for some drake files.
value = re.sub(' xmlns="[^"]+"', "", value, count=1)
return _xml2obj(et.fromstring(value))
# value = re.sub(' xmlns="[^"]+"', "", value, count=1)
parser = et.XMLParser(remove_blank_text=True, remove_comments=True, recover=True)
return _xml2obj(et.fromstring(value, parser))


def load_file(filename: str) -> XMLNode:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies = [
"pyyaml",
"numpy",
"lark",
"lxml"
]
dynamic = ["version"]

Expand Down

0 comments on commit 0400f1f

Please sign in to comment.