Fix config path resolution for one-click runners
This commit is contained in:
@@ -7,7 +7,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
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):
|
def run(cmd):
|
||||||
@@ -35,24 +35,34 @@ def parse_args():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
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():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
base_dir = Path(__file__).resolve().parent
|
base_dir = Path(__file__).resolve().parent
|
||||||
config_path = Path(args.config)
|
config_path = resolve_config_path(base_dir, args.config)
|
||||||
with open(config_path, "r", encoding="utf-8") as f:
|
with open(config_path, "r", encoding="utf-8") as f:
|
||||||
cfg = json.load(f)
|
cfg = json.load(f)
|
||||||
|
|
||||||
# Resolve config path without duplicating base_dir on Windows when user passes example/config.json
|
|
||||||
if config_path.is_absolute():
|
|
||||||
config_path = resolve_path(config_path.parent, config_path)
|
|
||||||
else:
|
|
||||||
candidate = base_dir / config_path
|
|
||||||
if candidate.exists():
|
|
||||||
config_path = resolve_path(candidate.parent, candidate)
|
|
||||||
elif config_path.exists():
|
|
||||||
config_path = resolve_path(config_path.parent, config_path)
|
|
||||||
else:
|
|
||||||
config_path = resolve_path(base_dir, config_path)
|
|
||||||
timesteps = cfg.get("timesteps", 200)
|
timesteps = cfg.get("timesteps", 200)
|
||||||
seq_len = cfg.get("sample_seq_len", cfg.get("seq_len", 64))
|
seq_len = cfg.get("sample_seq_len", cfg.get("seq_len", 64))
|
||||||
batch_size = cfg.get("sample_batch_size", cfg.get("batch_size", 2))
|
batch_size = cfg.get("sample_batch_size", cfg.get("batch_size", 2))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
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):
|
def run(cmd):
|
||||||
@@ -32,22 +32,32 @@ def parse_args():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def resolve_config(base_dir: Path, cfg_arg: str) -> Path:
|
def resolve_config_path(base_dir: Path, cfg_arg: str) -> Path:
|
||||||
config_path = Path(cfg_arg)
|
p = Path(cfg_arg)
|
||||||
if config_path.is_absolute():
|
if p.is_absolute():
|
||||||
return Path(resolve_path(config_path.parent, config_path))
|
if p.exists():
|
||||||
candidate = base_dir / config_path
|
return p.resolve()
|
||||||
if candidate.exists():
|
raise SystemExit(f"config not found: {p}")
|
||||||
return Path(resolve_path(candidate.parent, candidate))
|
|
||||||
if config_path.exists():
|
repo_dir = base_dir.parent
|
||||||
return Path(resolve_path(config_path.parent, config_path))
|
candidates = [p, base_dir / p, repo_dir / p]
|
||||||
return Path(resolve_path(base_dir, config_path))
|
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():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
base_dir = Path(__file__).resolve().parent
|
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:
|
with open(config_path, "r", encoding="utf-8") as f:
|
||||||
cfg = json.load(f)
|
cfg = json.load(f)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user