GeezerVison is showing github.com — Use a special technique to remove git repos on Windows by mdboom · Pull Request #442 · python/bench_runner
Conversation
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 PR adds a Windows-aware smart_rmtree to clear read-only flags before deletion, switches clone to use it, and documents the fix in the changelog.
- Introduce
smart_rmtree in bench_runner/util.py to handle read-only files on Windows
- Update
bench_runner/git.py to call util.smart_rmtree instead of shutil.rmtree
- Record the Windows fix in
CHANGELOG.md
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File |
Description |
| bench_runner/util.py |
Add smart_rmtree variants for Windows and default fallback |
| bench_runner/git.py |
Replace shutil.rmtree with util.smart_rmtree in clone |
| CHANGELOG.md |
Add entry for Windows repo-removal bugfix |
Comments suppressed due to low confidence (3)
bench_runner/util.py:112
- We should add a test to verify that
smart_rmtree correctly removes directories containing read-only files on Windows platforms.
def smart_rmtree(path: PathLike) -> None:
bench_runner/util.py:115
- The code calls
os.access and os.chmod but os is not imported in this file, leading to a NameError. Add import os at the top.
if not os.access(path, os.W_OK):
bench_runner/util.py:132
- The handler references undefined name
exc. It should use the error parameter (e.g. raise error[1]).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+110
to
+135
|
|
if sys.version_info >= (3, 12):
|
|
|
|
|
|
def smart_rmtree(path: PathLike) -> None:
|
|
|
def onexc(func, path, exc):
|
|
|
# Is the error an access error?
|
|
|
if not os.access(path, os.W_OK):
|
|
|
os.chmod(path, stat.S_IWUSR)
|
|
|
func(path)
|
|
|
else:
|
|
|
raise exc
|
|
|
|
|
|
shutil.rmtree(path, onexc=onexc)
|
|
|
|
|
|
else:
|
|
|
|
|
|
def smart_rmtree(path: PathLike) -> None:
|
|
|
def onerror(func, path, error):
|
|
|
# Is the error an access error?
|
|
|
if not os.access(path, os.W_OK):
|
|
|
os.chmod(path, stat.S_IWUSR)
|
|
|
func(path)
|
|
|
else:
|
|
|
raise exc[1]
|
|
|
|
|
|
shutil.rmtree(path, onerror=onerror)
|
|
|
|
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.
[nitpick] The Windows-specific smart_rmtree logic is duplicated for pre-3.12 and post-3.12 branches. Consider extracting shared code into a single helper to reduce duplication.
|
if sys.version_info >= (3, 12): |
|
|
|
def smart_rmtree(path: PathLike) -> None: |
|
def onexc(func, path, exc): |
|
# Is the error an access error? |
|
if not os.access(path, os.W_OK): |
|
os.chmod(path, stat.S_IWUSR) |
|
func(path) |
|
else: |
|
raise exc |
|
|
|
shutil.rmtree(path, onexc=onexc) |
|
|
|
else: |
|
|
|
def smart_rmtree(path: PathLike) -> None: |
|
def onerror(func, path, error): |
|
# Is the error an access error? |
|
if not os.access(path, os.W_OK): |
|
os.chmod(path, stat.S_IWUSR) |
|
func(path) |
|
else: |
|
raise exc[1] |
|
|
|
shutil.rmtree(path, onerror=onerror) |
|
|
|
def handle_access_error(func, path, exc_info): |
|
# Is the error an access error? |
|
if not os.access(path, os.W_OK): |
|
os.chmod(path, stat.S_IWUSR) |
|
func(path) |
|
else: |
|
raise exc_info[1] if isinstance(exc_info, tuple) else exc_info |
|
|
|
def smart_rmtree(path: PathLike) -> None: |
|
if sys.version_info >= (3, 12): |
|
shutil.rmtree(path, onexc=lambda func, path, exc: handle_access_error(func, path, exc)) |
|
else: |
|
shutil.rmtree(path, onerror=lambda func, path, error: handle_access_error(func, path, error)) |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|