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

Replaced str with Path #1919

Merged
merged 3 commits into from
Jun 29, 2024
Merged

Replaced str with Path #1919

merged 3 commits into from
Jun 29, 2024

Conversation

varonroy
Copy link
Contributor

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Changes

In Rust, whenever dealing with the file system, it is recommended to use the Path and PathBuf structs instead of str and String. In the burn code though, str is often used to describe a file path or a directory. This PR changes these instances to use Path.

Testing

Since str can be safely converted to Path, this is a drop-in replacement for the previous code. Aside of running ./run-checks, I've also tested it on an external project.

Copy link

codecov bot commented Jun 22, 2024

Codecov Report

Attention: Patch coverage is 35.82090% with 43 lines in your changes missing coverage. Please review.

Project coverage is 85.04%. Comparing base (a5dfb87) to head (77c0890).
Report is 13 commits behind head on main.

Files Patch % Lines
crates/burn-train/src/checkpoint/file.rs 0.00% 17 Missing ⚠️
crates/burn-train/src/learner/builder.rs 0.00% 13 Missing ⚠️
...rates/burn-train/src/learner/application_logger.rs 0.00% 8 Missing ⚠️
crates/burn-train/src/logger/file.rs 44.44% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1919      +/-   ##
==========================================
- Coverage   85.44%   85.04%   -0.41%     
==========================================
  Files         788      793       +5     
  Lines       92483    94600    +2117     
==========================================
+ Hits        79021    80449    +1428     
- Misses      13462    14151     +689     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nathanielsimard nathanielsimard left a comment

Choose a reason for hiding this comment

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

Thanks for the improvement, I only have one question :)

}

impl FileApplicationLoggerInstaller {
/// Create a new file application logger.
pub fn new(path: &str) -> Self {
pub fn new(path: impl AsRef<Path>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to have AsRef<Path> or Into<PatBuf>? If &str also implements Into<PathBuf> I think it might be more flexible, otherwise maybe AsRef<Path> is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I don't know which one is better. In this situation I think either one will work just fine.

Copy link
Collaborator

@Luni-4 Luni-4 Jun 26, 2024

Choose a reason for hiding this comment

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

It depends on the path usage, if a path must be only read then AsRef<Path> would be better, otherwise a Into<PathBuf> is preferred. We can have a look at how a path is treated internally in my opinion

Copy link
Contributor Author

@varonroy varonroy Jun 29, 2024

Choose a reason for hiding this comment

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

I noticed that this PR is still open. Are there any changes you would like me to make before merging it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use AsRef as the default choice for most file system operations in the codebase. This provides flexibility and efficiency for reading paths. We should only use Into<PathBuf> when we specifically need to own or modify the path data.

Copy link
Collaborator

@antimora antimora left a comment

Choose a reason for hiding this comment

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

Overall LGTM. There is one minor fix probably needed, otherwise it looks approvable to me.

crates/burn-train/src/logger/file.rs Outdated Show resolved Hide resolved
@antimora
Copy link
Collaborator

Thanks for fixing. Once the CI testing is fixed we can merge

@antimora antimora merged commit a7efc10 into tracel-ai:main Jun 29, 2024
14 checks passed
@antimora
Copy link
Collaborator

Merged. Thank you very much for your contribution!

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.

None yet

4 participants