Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lxml dependency #57

Merged
merged 9 commits into from
Apr 1, 2020
Merged

Remove lxml dependency #57

merged 9 commits into from
Apr 1, 2020

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Mar 13, 2020

Continues #40 which is a continuation from #32. This removes the dependency on lxml.

EricCousineau-TRI and others added 8 commits March 12, 2020 17:39
Co-authored-by: Tully Foote <tfoote@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
# TODO(eacousineau): This does not preserve attribute order. Fix it.
dom = minidom.parseString(ET.tostring(rootXml))
xml_string = ""
lines = dom.toprettyxml(indent=" ").split("\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had two major comments on the original PR.

The first one was about pretty printing the output. That one isn't super-important, but was something that the old one did. It looks like this one is doing that as well, which is good, and takes care of that point.

The second point was about preserving XML comments, which lxml does, but minidom does not. I guess we have to answer whether that is an important use case, and whether we can make that happen with minidom. I don't know that answer to either one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the melodic-devel branch is explicitly filtering XML comments out. Is there another API in this repo that gives access to them?

def xml_children(node):
children = node.getchildren()
def predicate(node):
return not isinstance(node, etree._Comment)
return list(filter(predicate, children))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally worried about round-tripping through this API, like:

from urdf_parser_py.urdf import URDF

with open('robot.urdf', 'r') as infp:
    robot = URDF.from_xml_string(infp.read())

print(robot.to_xml_string())

But you are right, we are already stripping out those comments. Personally I think that is a bug, but that is orthogonal to this PR. So I think we can proceed.

@@ -580,7 +580,7 @@ def to_xml(self):
""" Creates an overarching tag and adds its contents to the node """
tag = self.XML_REFL.tag
assert tag is not None, "Must define 'tag' in reflection to use this function" # noqa
doc = etree.Element(tag)
doc = ET.Element(tag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we are inheriting ET by importing from basics.* at the top, but I think it would be a bit better to explicitly do it at the top of this file:

from xml.etree import ElementTree as ET

Minor comment, though, I'll leave it to you whether you think we should do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the * import from core.py in 0ae7259 . sdf and urdf also import *, but I'd like to fix that in a follow up PR.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a quick look at 0ae7259 , just to try to make sure we got all of the imports. Looks pretty good to me, though we'd need more comprehensive tests to be sure.

Good to merge from me, assuming it passes the tests we already have.

@sloretz sloretz merged commit 22f3a60 into melodic-devel Apr 1, 2020
@sloretz sloretz deleted the remove_lxml branch April 1, 2020 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants