mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix: handle broken dashboard dist symlink in hatch build hook for AUR compatibility
This commit is contained in:
@@ -17,7 +17,6 @@ When enabled, this hook:
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from logging import getLogger
|
||||
from pathlib import Path
|
||||
|
||||
@@ -38,17 +37,23 @@ class CustomBuildHook(BuildHookInterface):
|
||||
if os.environ.get("ASTRBOT_BUILD_DASHBOARD", "").strip() != "1":
|
||||
# Ensure the target directory and a placeholder exist so the wheel
|
||||
# build does not fail when artifacts = ["..."] is declared.
|
||||
# Handle the case where dist_target might be a broken symlink (e.g. in AUR builds)
|
||||
if dist_target.is_symlink() or dist_target.is_file():
|
||||
dist_target.unlink()
|
||||
|
||||
dist_target.mkdir(parents=True, exist_ok=True)
|
||||
if not dist_target.exists() or not any(dist_target.iterdir()):
|
||||
if not any(dist_target.iterdir()):
|
||||
placeholder = dist_target / ".placeholder"
|
||||
placeholder.write_text("# dashboard placeholder\n")
|
||||
return
|
||||
|
||||
if not dashboard_src.exists():
|
||||
logger.warning(
|
||||
"[hatch_build] 'dashboard/' directory not found: skipping dashboard build.",
|
||||
file=sys.stderr,
|
||||
"[hatch_build] 'dashboard/' directory not found: skipping dashboard build."
|
||||
)
|
||||
if dist_target.is_symlink() or dist_target.is_file():
|
||||
dist_target.unlink()
|
||||
|
||||
dist_target.mkdir(parents=True, exist_ok=True)
|
||||
placeholder = dist_target / ".placeholder"
|
||||
placeholder.write_text("# dashboard placeholder\n")
|
||||
@@ -73,17 +78,22 @@ class CustomBuildHook(BuildHookInterface):
|
||||
|
||||
if not dist_src.exists():
|
||||
logger.warning(
|
||||
"[hatch_build] dashboard/dist not found after build: skipping copy.",
|
||||
file=sys.stderr,
|
||||
"[hatch_build] dashboard/dist not found after build: skipping copy."
|
||||
)
|
||||
if dist_target.is_symlink() or dist_target.is_file():
|
||||
dist_target.unlink()
|
||||
|
||||
dist_target.mkdir(parents=True, exist_ok=True)
|
||||
placeholder = dist_target / ".placeholder"
|
||||
placeholder.write_text("# dashboard placeholder\n")
|
||||
return
|
||||
|
||||
# ── Copy into the Python package tree ───────────────────────────────
|
||||
if dist_target.exists():
|
||||
if dist_target.is_symlink() or dist_target.is_file():
|
||||
dist_target.unlink()
|
||||
elif dist_target.exists():
|
||||
shutil.rmtree(dist_target)
|
||||
|
||||
shutil.copytree(dist_src, dist_target)
|
||||
logger.info(
|
||||
f"[hatch_build] Dashboard dist copied → {dist_target.relative_to(root)}"
|
||||
|
||||
Reference in New Issue
Block a user