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

Add in support for the version tag. #52

Merged
merged 3 commits into from
Jan 13, 2020
Merged

Conversation

clalancette
Copy link
Contributor

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

Just like in urdfdom, add support for the version tag in the URDF XML. Note that I ended up adding the version tag by hand to all of the round-trip tests so that they pass; there are other tests that test the lack of a version tag, so I think this is fine. @sloretz @scpeters FYI.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
xml = '''<?xml version="1.0"?>
<robot name="test" version="foo">
</robot>'''
#self.assertRaises(xmlr.core.ParseError, self.parse, xml)

Choose a reason for hiding this comment

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

can this commented line be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, definitely, just a leftover from testing. Done in 9f78b7f

@scpeters
Copy link

this also looks good; just one more minor comment

@scpeters
Copy link

The concerns about parsing floats in ros/urdfdom#133 (comment) are relevant here too

@scpeters
Copy link

scpeters commented Dec 6, 2019

I think we need to update the version parsing here too

@clalancette
Copy link
Contributor Author

I think we need to update the version parsing here too

Yeah, definitely, I just ran out of time yesterday. I'll get to this early next week.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor Author

Yeah, definitely, I just ran out of time yesterday. I'll get to this early next week.

OK, late this week, but I did finally get it done. I switched this to a string now, and updated the tests to match the C++ ones in 9f78b7f. This is ready for another review.

@clalancette clalancette mentioned this pull request Jan 6, 2020

def test_version_attribute_no_major_number(self):
xml = '''<?xml version="1.0"?>
<robot name="test" version="1.">
Copy link

Choose a reason for hiding this comment

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

for no_major_number, should this be version=".0"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, definitely. That was a mistake, and it actually showed a bug. Will fix.


def test_version_attribute_negative_minor_number(self):
xml = '''<?xml version="1.0"?>
<robot name="test" version="-1.0">
Copy link

Choose a reason for hiding this comment

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

1.-0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sigh, yes.


split = self.version.split(".")
if len(split) != 2:
raise Exception("The version attribute should be in the form 'x.y'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend a custom exception, but ValueError would fit too. Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I went back and forth on making a custom exception. I think I'll go with "ValueError", as that seems to make the most sense to me.

@@ -533,6 +533,20 @@ def get_root(self):
assert root is not None, "No roots detected, invalid URDF."
return root

def post_read_xml(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

What calls this function? I can't find any uses of it.

Copy link
Contributor Author

@clalancette clalancette Jan 8, 2020

Choose a reason for hiding this comment

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

It's magic :). The Robot class is a sub-class of xmlr.Object, which defines an empty version of post_read_xml. In turn, this method is called directly after reading in the XML (see here). So I just overrode it in the Robot sub-class.

src/urdf_parser_py/urdf.py Show resolved Hide resolved
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor Author

Thanks for the reviews! I've made fixes corresponding to the reviews in e832a00. @sloretz @scpeters ready for another round.

@clalancette
Copy link
Contributor Author

Thanks! Merging.

@clalancette clalancette merged commit c0a75a2 into melodic-devel Jan 13, 2020
@clalancette clalancette deleted the version-tag branch January 13, 2020 21:13
clalancette added a commit that referenced this pull request Jan 22, 2020
* Add in support for the version tag.

Cherry-picked from the melodic-devel branch commit
c0a75a2

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
clalancette added a commit that referenced this pull request Mar 10, 2020
* Add in support for the version tag.

Cherry-picked from the melodic-devel branch commit
c0a75a2

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@audrow audrow mentioned this pull request Nov 17, 2022
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