Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions bench_runner/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import contextlib
import datetime
from pathlib import Path
import shutil
import subprocess
import re

Expand All @@ -14,6 +13,7 @@


from .util import PathLike
from . import util


def get_log(
Expand Down Expand Up @@ -147,7 +147,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

Expand Down
32 changes: 32 additions & 0 deletions bench_runner/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
import shutil
import subprocess
import stat
import sys
from typing import Iterable, Iterator, Literal, TypeAlias, Union

Expand Down Expand Up @@ -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, 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]

shutil.rmtree(path, onerror=onerror)

else:
smart_rmtree = shutil.rmtree


if os.getenv("GITHUB_ACTIONS") == "true":

@contextlib.contextmanager
Expand Down