Fix config path resolution for one-click runners
This commit is contained in:
@@ -7,7 +7,7 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from platform_utils import safe_path, is_windows, resolve_path
|
||||
from platform_utils import safe_path, is_windows
|
||||
|
||||
|
||||
def run(cmd):
|
||||
@@ -32,22 +32,32 @@ def parse_args():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def resolve_config(base_dir: Path, cfg_arg: str) -> Path:
|
||||
config_path = Path(cfg_arg)
|
||||
if config_path.is_absolute():
|
||||
return Path(resolve_path(config_path.parent, config_path))
|
||||
candidate = base_dir / config_path
|
||||
if candidate.exists():
|
||||
return Path(resolve_path(candidate.parent, candidate))
|
||||
if config_path.exists():
|
||||
return Path(resolve_path(config_path.parent, config_path))
|
||||
return Path(resolve_path(base_dir, config_path))
|
||||
def resolve_config_path(base_dir: Path, cfg_arg: str) -> Path:
|
||||
p = Path(cfg_arg)
|
||||
if p.is_absolute():
|
||||
if p.exists():
|
||||
return p.resolve()
|
||||
raise SystemExit(f"config not found: {p}")
|
||||
|
||||
repo_dir = base_dir.parent
|
||||
candidates = [p, base_dir / p, repo_dir / p]
|
||||
if p.parts and p.parts[0] == "example":
|
||||
trimmed = Path(*p.parts[1:]) if len(p.parts) > 1 else Path()
|
||||
if str(trimmed):
|
||||
candidates.extend([base_dir / trimmed, repo_dir / trimmed])
|
||||
|
||||
for c in candidates:
|
||||
if c.exists():
|
||||
return c.resolve()
|
||||
|
||||
tried = "\n".join(str(c) for c in candidates)
|
||||
raise SystemExit(f"config not found: {cfg_arg}\ntried:\n{tried}")
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
base_dir = Path(__file__).resolve().parent
|
||||
config_path = resolve_config(base_dir, args.config)
|
||||
config_path = resolve_config_path(base_dir, args.config)
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
cfg = json.load(f)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user