GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use a special technique to remove git repos on Windows by mdboom · Pull Request #442 · python/bench_runner

Conversation

@mdboom

@mdboom mdboom commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mdboom
mdboom requested a review from Copilot June 5, 2025 15:29
Copilot AI reviewed Jun 5, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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]).
raise exc[1]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bench_runner/util.py
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)

Copilot AI Jun 5, 2025

Copy link

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
mdboom added 3 commits June 5, 2025 11:31
@mdboom
Use a special technique to remove git repos on Windows
ae078e9
@mdboom
Add CHANGELOG
7df5859
@mdboom
Lint
46e3954
@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 python:main Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@mdboom
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.