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

Refactor SDF handling logic for non-existing string paths #50

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

flferretti
Copy link
Collaborator

The non-existing paths will be handled by pathlib.Path.read_text(), eventually raising a FileNotFoundError.

@flferretti
Copy link
Collaborator Author

The pre-commit.ci is failing as #48 needs to be merged before this

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

I'm not 100% sure that the new logic covers entirely the old logic. Also, the previous refactoring might have introduced some unchecked cases.

It's probably worth to have a unit test for such a core component of the library like loading the supported types of resources.

@flferretti
Copy link
Collaborator Author

flferretti commented Nov 11, 2024

I'm not 100% sure that the new logic covers entirely the old logic. Also, the previous refactoring might have introduced some unchecked cases.

It's probably worth to have a unit test for such a core component of the library like loading the supported types of resources.

I added additional tests and refactored forcing is_urdf to be more robust

src/rod/sdf/sdf.py Outdated Show resolved Hide resolved
Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

I think the three original cases were correct, and now something is missing:

  1. If the resource is a path, expect that is exists and read its content.
  2. If the resource is a string:
  • a) if its length is shorter than the max path length, check if it's a file. If it is, read its content, otherwise treat it as a string containing the URDF/SDF.
  • b) if its length is longer than the max path length, treat is as a string containing the URDF/SDF.

How is 2a handled now? The logic seems changed.

@flferretti
Copy link
Collaborator Author

I think the three original cases were correct, and now something is missing:

1. If the resource is a path, expect that is exists and read its content.

2. If the resource is a string:


* a) if its length is shorter than the max path length, check if it's a file. If it is, read its content, otherwise treat it as a string containing the URDF/SDF.

* b) if its length is longer than the max path length, treat is as a string containing the URDF/SDF.

How is 2a handled now? The logic seems changed.

Solved by rebase. I had to make the assumption that the passed string path has an extension, I couldn't find any other way to distinguish between a URDF shorter than MAX_PATH and a string path.

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

Great! Now it looks much better, thanks @flferretti.

src/rod/sdf/sdf.py Show resolved Hide resolved
src/rod/sdf/sdf.py Show resolved Hide resolved
@flferretti flferretti merged commit d931d20 into main Nov 12, 2024
29 checks passed
@flferretti flferretti deleted the flferretti-patch-2 branch November 12, 2024 11:24
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.

4 participants