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

Added JointAxis Python interface #960

Merged
merged 10 commits into from
Apr 22, 2022
Merged

Added JointAxis Python interface #960

merged 10 commits into from
Apr 22, 2022

Conversation

ahcorde
Copy link
Collaborator

@ahcorde ahcorde commented Apr 11, 2022

Signed-off-by: ahcorde ahcorde@gmail.com

🎉 New feature

This PR is part of this meta ticket #931

Summary

Added JointAxis Python interface

Test it

from sdformat import JointAxis

jointAxis = JointAxis()

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Verified

This commit was signed with the committer’s verified signature.
scpeters Steve Peters
Signed-off-by: Alejandro Hernández <ahcorde@gmail.com>
@ahcorde ahcorde added the scripting Scripting interfaces to Ignition label Apr 11, 2022
@ahcorde ahcorde requested review from azeey and scpeters as code owners April 11, 2022 14:57
@ahcorde ahcorde self-assigned this Apr 11, 2022
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Apr 11, 2022
ahcorde added 2 commits April 18, 2022 12:34

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was signed with the committer’s verified signature.
scpeters Steve Peters
Signed-off-by: ahcorde <ahcorde@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2022

Codecov Report

Merging #960 (7b09b64) into main (bb84733) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #960   +/-   ##
=======================================
  Coverage   66.66%   66.66%           
=======================================
  Files           2        2           
  Lines          27       27           
=======================================
  Hits           18       18           
  Misses          9        9           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb84733...7b09b64. Read the comment docs.


# expect errors when trying to resolve axis without graph
vec3 = Vector3d()
self.assertTrue(axis.resolve_xyz(vec3))
Copy link
Member

Choose a reason for hiding this comment

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

it is counter-intuitive that the resolve function evaluates to True on failure (because the Errors vector is not empty) and False on success (when Errors is empty).

@azeey is there anything we can do to reverse this? Can we create a custom binding for the sdf::Errors vector that reverses this logic?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since sdf::Errors is a std::vector of sdf::Error objects, I think it's automatically converted to python list of sdf::Error objects. I'm not sure if it would be possible to reverse the logic for checking if a list is empty. I think it would be easier to change the test assertion:

 def assert_no_errors(errs):
    self.assertFalse(errs)

and use assert_no_errors here.

Copy link
Member

Choose a reason for hiding this comment

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

that helper would certainly make our tests more readable, but I think it would be a defect in our python API if any method that returns an sdf::Errors object would resolves to True in the presence of errors and False when there are no errors. I know that C treats a return code == 0 as success, but this isn't C. It just seems backwards to me.

if axis.resolve_xyz(vec3):
    # what do you expect here, success right?

it seems like a big usability issue to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what about using len ?

if len(axis.resolve_xyz(vec3)) == 0:
   ...

Copy link
Member

Choose a reason for hiding this comment

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

what about using len ?

if len(axis.resolve_xyz(vec3)) == 0:
   ...

that's a nice way to do it

maybe I'm overthinking it, but I think now is the time to try to fix this if we think it's worth fixing

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does feel backward when written that way because that feels like you would get a Result object back from that function call. For someone who expects an Errors object, reverting the logic would still lead to confusion because one might do:

errors = axis.resolve_xyz(vec3)
if errors:
  # Handle errors
  print(errors) # or something more important

I believe the pythonic way to do error handling is to use exceptions, so a potential solution would be to wrap the function so that it raises an exception if it has an error.

Copy link
Member

Choose a reason for hiding this comment

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

I believe the pythonic way to do error handling is to use exceptions, so a potential solution would be to wrap the function so that it raises an exception if it has an error.

yes, this feels like a more proper way to do things. I think for the time being we can continue using a direct mapping of the API, but I'll add a bullet point to our meta-ticket suggesting error-handling with exceptions

thanks for the great suggestion!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done here 0fae02b

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still see self.assertTrue(axis.resolve_xyz(vec3)). Are you planning to
change it?

ahcorde added 6 commits April 19, 2022 22:11

Verified

This commit was signed with the committer’s verified signature.
scpeters Steve Peters

Verified

This commit was signed with the committer’s verified signature.
scpeters Steve Peters
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from scpeters April 20, 2022 18:40

# expect errors when trying to resolve axis without graph
vec3 = Vector3d()
self.assertTrue(axis.resolve_xyz(vec3))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still see self.assertTrue(axis.resolve_xyz(vec3)). Are you planning to
change it?

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from azeey April 21, 2022 20:03
@ahcorde ahcorde merged commit f2e047a into main Apr 22, 2022
@ahcorde ahcorde deleted the ahcorde/python/jointaxis branch April 22, 2022 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden mujoco scripting Scripting interfaces to Ignition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants