Skip to content

Conversation

@mdboom
Copy link
Contributor

@mdboom mdboom commented Jun 5, 2025

No description provided.

@mdboom mdboom requested a review from Copilot June 5, 2025 15:29
Copy link
Contributor

Copilot AI left a 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]).
raise exc[1]

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)

Copy link

Copilot AI Jun 5, 2025

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
@mdboom mdboom force-pushed the windows-git-rmtree branch from 0ca860b to 46e3954 Compare June 5, 2025 15:31
@mdboom mdboom merged commit f09a85a into faster-cpython:main Jun 5, 2025
6 checks passed
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.

1 participant