""" Complete path fix for all 48 scripts """ import os from pathlib import Path scripts_dir = Path("c:/numerai48models/scripts") all_scripts = list(scripts_dir.rglob("*.py")) fixed = 0 for script in all_scripts: try: with open(script, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() # Determine tournament from path if 'main' in str(script): tournament = 'main' elif 'signals' in str(script): tournament = 'signals' elif 'crypto' in str(script): tournament = 'crypto' else: continue # Find and replace the configuration section if '# CONFIGURATION' in content and 'BASE_DIR' in content: # Replace entire config section with working version lines = content.split('\n') new_lines = [] in_config = False skip_until_print = False for i, line in enumerate(lines): if '# CONFIGURATION' in line: in_config = True new_lines.append(line) new_lines.append('# ' + '=' * 44) new_lines.append('TESTING_MODE = os.getenv("TESTING_MODE", "true").lower() == "true"') new_lines.append('if TESTING_MODE:') new_lines.append(f' BASE_DIR = Path("c:/numerai48models")') new_lines.append(f' MODEL_DIR = BASE_DIR / "models" / "{tournament}"') new_lines.append(f' DATA_DIR = BASE_DIR / "data" / "{tournament}"') new_lines.append(f' OUTPUT_DIR = BASE_DIR / "submissions" / "{tournament}"') new_lines.append('else:') new_lines.append(' BASE_DIR = Path("/app")') new_lines.append(f' MODEL_DIR = BASE_DIR / "models" / "{tournament}"') new_lines.append(f' DATA_DIR = BASE_DIR / "data" / "{tournament}"') new_lines.append(f' OUTPUT_DIR = BASE_DIR / "submissions" / "{tournament}"') new_lines.append('') new_lines.append('for dir_path in [DATA_DIR, OUTPUT_DIR]:') new_lines.append(' dir_path.mkdir(exist_ok=True, parents=True)') skip_until_print = True elif skip_until_print and 'print(f"[FOLDER] Model directory' in line: skip_until_print = False new_lines.append(line) elif not skip_until_print: new_lines.append(line) content = '\n'.join(new_lines) with open(script, 'w', encoding='utf-8', errors='ignore') as f: f.write(content) print(f"[OK] {script.relative_to(scripts_dir)}") fixed += 1 except Exception as e: print(f"[ERR] {script.name}: {e}") print(f"\nFixed {fixed} scripts!")