-
Notifications
You must be signed in to change notification settings - Fork 39
Pathlib and perf #823
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
base: master
Are you sure you want to change the base?
Pathlib and perf #823
Conversation
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.
Pull Request Overview
This pull request modernizes the codebase by replacing os.path
and os
module calls with pathlib.Path
operations, providing better performance and more readable code.
Key changes:
- Replaces all
os.path
operations with equivalentpathlib.Path
methods - Removes unused
os
module imports - Improves code readability and maintainability through modern Python path handling
# Use pathlib for cleaner path operations | ||
return Path(full_path).name |
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.
The function name get_directory_name_from_full_path
suggests it should return a directory name, but Path.name
returns the final component of the path (which could be a file). The original code used os.path.basename(os.path.split(normalized_path)[1])
which had different behavior. This change may break functionality if callers expect directory-specific behavior.
# Use pathlib for cleaner path operations | |
return Path(full_path).name | |
# Return the name of the parent directory, even if the path ends with a file | |
return Path(full_path).parent.name |
Copilot uses AI. Check for mistakes.
capture_output=True, | ||
text=True, | ||
cwd=os_path.dirname(__file__), | ||
cwd=Path(__file__).parent, |
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.
The cwd
parameter expects a string path, but Path(__file__).parent
returns a Path object. This should be converted to string: cwd=str(Path(__file__).parent)
cwd=Path(__file__).parent, | |
cwd=str(Path(__file__).parent), |
Copilot uses AI. Check for mistakes.
git_hash_file = os_path.join(os_path.dirname(__file__), "git_hash.txt") | ||
git_hash_file = Path(__file__).parent / "git_hash.txt" | ||
try: | ||
with open(git_hash_file, encoding="utf-8") as 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.
The open()
function expects a string path, but git_hash_file
is a Path object. Convert to string: with open(str(git_hash_file), encoding=\"utf-8\") as file:
with open(git_hash_file, encoding="utf-8") as file: | |
with open(str(git_hash_file), encoding="utf-8") as file: |
Copilot uses AI. Check for mistakes.
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Test Results1 743 tests 1 719 ✅ 52s ⏱️ For more details on these failures, see this check. Results for commit d783fcd. ♻️ This comment has been updated with latest results. |
867eac5
to
3541d9c
Compare
3541d9c
to
d783fcd
Compare
No description provided.