-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add AssetPath::resolve_path and resolve_embed_path methods #22416
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 AssetPath::resolve_path and resolve_embed_path methods #22416
Conversation
These new methods accept &AssetPath instead of &str, avoiding the need to stringify and re-parse when the caller already has an AssetPath. Fixes bevyengine#22239
These new methods accept &AssetPath instead of &str, avoiding the need to stringify and re-parse when the caller already has an AssetPath. Fixes bevyengine#22239
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
|
Very clean work; thank you :) |
|
My only concern is that this propagates a pattern that we've been wanting to get rid of for a long time (but have never got around to fixing). Specifically,
But asset paths themselves are not file paths, they are more like URLs. |
|
Thanks @alice-i-cecile for the compliment and thanks @viridia for the detailed feedback, that actually makes sense. I agree This PR intentionally kept behavior identical to the existing I thought of 2 things could be done rn :
I’m happy to do either.. |
|
If we commit to doing a follow-up PR then it would alleviate my concerns. |
Shatur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can sneak this into 0.18 since it's not a breaking change, but I'd probably rename old methods into *_str and keep path variants as "default" in a follow-up.
crates/bevy_asset/src/path.rs
Outdated
| ) -> AssetPath<'static> { | ||
| let mut base_path = PathBuf::from(self.path()); | ||
| if replace && !self.path.to_str().unwrap().ends_with('/') { | ||
| // No error if base is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why (per RFC 1808) in the comment was removed?
crates/bevy_asset/src/path.rs
Outdated
| /// Resolves `path` relative to `self`, using the same rules as [`AssetPath::resolve`], | ||
| /// but without reparsing from a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the description of resolve instead and mention that it parses the asset path from the string?
|
@Shatur @alice-i-cecile On it |
…suit the method name change occured. replacing back the RFC 1808 reference.
|
I meant to rename in a follow-up PR some time later because this would potentially allow us to include this change in 0.18. But if it's easier for you to do it now - it's okay, not that important to have this in 0.18 🙂 |
|
@Shatur oh really, sorry didn't catch this up! anyway I'm up for the night dodging studying for data engineering final, it is ok. and sorry for the many mentions, we are more than 2 in the discussion, just so I don't mix things up. |
|
Wonderful analogy with a high-level end-to-end object oriented solution Mr. @Eyad3skr |
|
anybody got an idea of why CI / markdownlint (pull_request) fails? |
|
Markdown errors can be found starting https://github.com/bevyengine/bevy/actions/runs/20803366790/job/59752575411?pr=22416#step:4:156; you need to expand the markdown section when looking at the job :) Thanks for your work here; I'll merge this once CI is passing! |
| pull_requests: [22416] | ||
| --- | ||
|
|
||
| # `AssetPath::resolve` and `resolve_embed` now take `&AssetPath` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to take a look at how other people write migration guides: https://github.com/bevyengine/bevy/tree/main/release-content/migration-guides
It's a bit verbose for such a simple change. I wouldn't even add "Before" and "After".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eyad3skr I didn't mean to remove the labels. I meant to remove the whole blocks with the before and after code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so migration part I just write it in plain English?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just a few sentences should be enough to explain the breaking change. Just take a look at the link I shared above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passed it finally.. the linter was confused between the real title from template and my text because I used H1 after the title, so I reduced it to H2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shatur Ok I will see now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's still overly verbose. Take a look at the migration guides I linked to you. You don't need headings, just write in plain English what was done (no need to write "# What was done"), how to migrate and why. It's obvious that if you have a string, it's more convenient to use the *_str methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, made it
|
|
||
| `AssetPath::resolve` and `AssetPath::resolve_embed` no longer accept `&str` and now take `&AssetPath` directly. The previous string-based APIs have been renamed to `resolve_str` and `resolve_embed_str`. | ||
|
|
||
| This change avoids unnecessary string allocation and parsing when an `AssetPath` is already available. To migrate, pass an `AssetPath` directly to `resolve` or `resolve_embed`; when working with strings, use the corresponding `*_str` methods instead. No behavioral or semantic changes were introduced. No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost perfect, last tiny change, can be applied directly from the browser 🙂 I think the last sentence doesn't add anything.
| This change avoids unnecessary string allocation and parsing when an `AssetPath` is already available. To migrate, pass an `AssetPath` directly to `resolve` or `resolve_embed`; when working with strings, use the corresponding `*_str` methods instead. No behavioral or semantic changes were introduced. | |
| This change avoids unnecessary string allocation and parsing when an `AssetPath` is already available. To migrate, pass an `AssetPath` directly to `resolve` or `resolve_embed`; when working with strings, use the corresponding `*_str` methods instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it, the linter failed anyway, needed a trailing newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, waiting for any updates. I'm trying to catch up anyway so I got no problem getting assigned this one too, thanks for the review and your effort!
Shatur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect now! Thank you.
Always! Thank you for the review, much appreciated! |
|
@alice-i-cecile this PR includes a breaking change, so we probably have to remove it from 0.18 😢 |
Objective
Fixes #22239
Solution
resolve_path(&AssetPath)- equivalent toresolve(&str)resolve_embed_path(&AssetPath)- equivalent toresolve_embed(&str)resolve_internalto use sharedresolve_from_partshelperTesting
resolve_path() ≡ resolve(&path.to_string())cargo test -p bevy_asset --lib path::testsHow to test