From ae078e9c2c28559c118178286c32f51eaafdca36 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 5 Jun 2025 11:27:55 -0400 Subject: [PATCH 1/3] Use a special technique to remove git repos on Windows --- bench_runner/git.py | 3 ++- bench_runner/util.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bench_runner/git.py b/bench_runner/git.py index 8070c39..04e4928 100644 --- a/bench_runner/git.py +++ b/bench_runner/git.py @@ -14,6 +14,7 @@ from .util import PathLike +from . import util def get_log( @@ -147,7 +148,7 @@ def clone( if is_hash and (dirname / ".git").is_dir() and get_git_hash(dirname) == branch: # This is a git repo, and the hash matches return - shutil.rmtree(dirname) + util.smart_rmtree(dirname) # Fetching a hash and fetching a branch require different approaches diff --git a/bench_runner/util.py b/bench_runner/util.py index e70d3f5..5b50f5a 100644 --- a/bench_runner/util.py +++ b/bench_runner/util.py @@ -5,6 +5,7 @@ from pathlib import Path import shutil import subprocess +import stat import sys from typing import Iterable, Iterator, Literal, TypeAlias, Union @@ -105,6 +106,37 @@ def valid_version(version: str) -> bool: return False +if sys.platform.startswith("win"): + 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) + +else: + smart_rmtree = shutil.rmtree + + if os.getenv("GITHUB_ACTIONS") == "true": @contextlib.contextmanager From 7df58599016509f16587e0b05438c757919fcadb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 5 Jun 2025 11:29:00 -0400 Subject: [PATCH 2/3] Add CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba9dae6..675a9c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Unreleased +### Bugfixes + +#### Removing a git repo on Windows fails + +One needs to remove the "read only" flags on certain files in the git repo in order to remove it. + ## 2.0.0 ### Moving more code to Python From 46e3954197c75a833b2a949417e14cc1d4634e31 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 5 Jun 2025 11:30:51 -0400 Subject: [PATCH 3/3] Lint --- bench_runner/git.py | 1 - bench_runner/util.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bench_runner/git.py b/bench_runner/git.py index 04e4928..0df312f 100644 --- a/bench_runner/git.py +++ b/bench_runner/git.py @@ -5,7 +5,6 @@ import contextlib import datetime from pathlib import Path -import shutil import subprocess import re diff --git a/bench_runner/util.py b/bench_runner/util.py index 5b50f5a..40e885d 100644 --- a/bench_runner/util.py +++ b/bench_runner/util.py @@ -123,13 +123,13 @@ def onexc(func, path, exc): else: def smart_rmtree(path: PathLike) -> None: - def onerror(func, path, error): + def onerror(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[1] + raise exc_info[1] shutil.rmtree(path, onerror=onerror)