-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Migrated file_ops.py
and scene_file_writer.py
from os.path to Pathlib
#2642
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
Conversation
Multiple commits are from differences between Path objects and WindowsPath objects and me not being able to test this on a Windows file system. |
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.
Thank you for your work! This looks good to me 👍
Thank you! Can you help resolve the merge conflict? |
Looking at the merge conflicts, I think it would be nice to have the Would you change those tests to pass paths as well? |
So then the methods would look like, with type hints as: def guarantee_existence(path: Path) -> Path:
if not path.exists():
path.mkdir(parents=True)
return path.resolve(strict=True)
def guarantee_empty_existence(path: Path) -> Path:
if path.exists():
shutil.rmtree(str(path))
path.mkdir(parents=True)
return path.resolve(strict=True)
def seek_full_path_from_defaults(file_name: str, default_dir: Path, extensions: list[str]) -> Path: |
Yep I’ll work on it today. Thanks for the feedback! |
for more information, see https://pre-commit.ci
Added the type hints to the methods in file_ops.py and changed the file_ops tests to use path lib |
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.
LGTM!
file_ops.py
and scene_file_writer.py
from os.path to Pathlib
Overview: What does this pull request change?
In
file_ops.py
andscene_file_writer.py
: Uses of str type file names have been mostly (see further information) converted to pathlib's Path objects. Uses ofos.path
methods have been converted to equivalent pathlib methods.Motivation and Explanation: Why and how do your changes improve the library?
We focused on the Issue/enhancement/feature request here
Migrating to Pathlib objects and methods conforms to the maintainability and "built-in" standards of the project. Generally, Pathlib tends to conform better to OOP standards in python than os.path. This refactoring contributes to making the project—and its path types—consistent.
Links to added or changed documentation pages
N/A
Further Information and Comments
There is still a single use of str-based path objects with self.sections_output_dir = "" (scene_file_writer.py:128). We considered /dev/null or NUL as a default path. We ultimately left it as a str object as the Path() default constructor creates a path to the current directory (instead of ""), which might cause unwanted issues with path concatenation.
Additionally, we ran pytest on the entire suite to ensure our changes did not introduce any unwanted I/O behavior.
Reviewer Checklist