mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: one autorun worktree path and checkout
This commit is contained in:
1 parent
6c92b0172e
commit
eec4ff9972
6 files changed
+29
-17
No files matched your search
@@ -35,7 +35,8 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from devtools.diskcleanup import ALERT_GB, apply, busy_paths, disk_line, inside, main_checkout, plan
|
||||
from core.gitclone import main_checkout
|
||||
from devtools.diskcleanup import ALERT_GB, apply, busy_paths, disk_line, inside, plan
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class GitRefused(RuntimeError):
|
||||
@@ -37,6 +38,17 @@ def required_git_lines(*args: str) -> list[str]:
|
||||
return _lines(result.stdout)
|
||||
|
||||
|
||||
def main_checkout(cwd: Path) -> Path:
|
||||
"""The main checkout of the clone holding cwd, also from a linked worktree,
|
||||
GitRefused when cwd is in no clone."""
|
||||
args = ("rev-parse", "--path-format=absolute", "--git-common-dir")
|
||||
result = _run(("-C", str(cwd), *args))
|
||||
if result.returncode:
|
||||
detail = result.stderr.strip() or f"exit {result.returncode}"
|
||||
raise GitRefused(f"git {' '.join(args)}: {detail}")
|
||||
return Path(result.stdout.strip()).parent
|
||||
|
||||
|
||||
# Where a clone with no remote naming the project keeps its main line, each
|
||||
# remote's names in the order tried.
|
||||
FALLBACK_REMOTES = ("upstream", "origin")
|
||||
|
||||
@@ -19,6 +19,10 @@ BIOS_DIR = "bios"
|
||||
DATA_DIRS_FILE = f"{PLATFORMS_DIR}/_data_dirs.yml"
|
||||
# Where generate_truth writes its models and diff_truth and export_native read them.
|
||||
TRUTH_DIR = "dist/truth"
|
||||
# The unattended runner's home, and the worktree it commits from, which disk
|
||||
# cleanup must never take for an idle session worktree.
|
||||
AUTORUN_DIR = ".cache/autorun"
|
||||
AUTORUN_WORKTREE = f"{AUTORUN_DIR}/worktree"
|
||||
|
||||
|
||||
def sanitize_pack_path(raw: str) -> str:
|
||||
|
||||
@@ -11,12 +11,13 @@ from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import AUTORUN_WORKTREE
|
||||
|
||||
GENERATED = re.compile(
|
||||
r"^(database\.json|install/.*\.json|exports/.*\.json|README\.md|CONTRIBUTING\.md"
|
||||
r"|website/src/data/[^/]+\.json)$"
|
||||
)
|
||||
KEPT_TMP = ("acquire",)
|
||||
AUTOMATION_WORKTREE = Path(".cache") / "autorun" / "worktree"
|
||||
ALERT_GB = 100
|
||||
|
||||
|
||||
@@ -37,12 +38,6 @@ def git(cwd: Path, *args: str, check: bool = True) -> str:
|
||||
return proc.stdout
|
||||
|
||||
|
||||
def main_checkout(cwd: Path) -> Path:
|
||||
"""The main checkout, also when run from inside a linked worktree."""
|
||||
common = git(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir").strip()
|
||||
return Path(common).parent
|
||||
|
||||
|
||||
def busy_paths() -> set[str]:
|
||||
"""Every working directory and open file of every readable process."""
|
||||
found: set[str] = set()
|
||||
@@ -100,7 +95,7 @@ def linked_worktrees(repo: Path) -> list[Path]:
|
||||
|
||||
def session_worktrees(repo: Path) -> list[Path]:
|
||||
"""Linked worktrees inside the checkout, the automation worktree aside."""
|
||||
keep = repo / AUTOMATION_WORKTREE
|
||||
keep = repo / AUTORUN_WORKTREE
|
||||
return [p for p in linked_worktrees(repo) if inside(p, repo) and p != keep]
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from pathlib import Path
|
||||
|
||||
from core.artifacts import TIMESTAMP_KEYS
|
||||
from core.hostguard import LockBusy, free_gb, global_lock, lock_busy
|
||||
from core.paths import AUTORUN_DIR, AUTORUN_WORKTREE
|
||||
from core.statefile import now_iso, save_state
|
||||
from unattended.breaker import may_push, refresh_breaker
|
||||
from unattended.jobs import AutorunError, BLOCKED, DEFERRED, FAILED, Job, OK, REFUSED, Step, job_env
|
||||
@@ -34,9 +35,6 @@ from unattended.worktree import (
|
||||
)
|
||||
|
||||
|
||||
AUTORUN_DIR = Path(".cache") / "autorun"
|
||||
|
||||
|
||||
ALERT_FREE_GB = 100
|
||||
LOG_DAYS = 30
|
||||
SEGFAULT_CODES = (139, -11)
|
||||
@@ -81,7 +79,7 @@ class Context:
|
||||
|
||||
@property
|
||||
def worktree(self) -> Path:
|
||||
return self.home / "worktree"
|
||||
return self.repo / AUTORUN_WORKTREE
|
||||
|
||||
@property
|
||||
def state_path(self) -> Path:
|
||||
|
||||
@@ -11,6 +11,8 @@ import subprocess
|
||||
from collections.abc import Callable, Sequence
|
||||
from pathlib import Path
|
||||
|
||||
from core.gitclone import GitRefused
|
||||
from core.gitclone import main_checkout as gitclone_main_checkout
|
||||
from core.paths import REPO_ROOT
|
||||
from unattended.jobs import AutorunError, BLOCKED, CommitRule, FAILED, token_env
|
||||
|
||||
@@ -158,7 +160,7 @@ def push_batch(worktree: Path, gate_base: str, regate: Callable[[], bool]) -> st
|
||||
|
||||
def main_checkout() -> Path:
|
||||
"""The main checkout, also when this script runs from a linked worktree."""
|
||||
proc = git(REPO_ROOT, "rev-parse", "--path-format=absolute", "--git-common-dir",
|
||||
check=False)
|
||||
common = Path(proc.stdout.strip()) if proc.returncode == 0 else REPO_ROOT / ".git"
|
||||
return common.parent
|
||||
try:
|
||||
return gitclone_main_checkout(REPO_ROOT)
|
||||
except GitRefused:
|
||||
return REPO_ROOT
|
||||
Reference in new issue
Block a user