Add 'export WORKSPACE' where it's used by embedded Python but not exported.
(apply: bool)
| 172 | |
| 173 | |
| 174 | def fix_workspace_export(apply: bool): |
| 175 | """Add 'export WORKSPACE' where it's used by embedded Python but not exported.""" |
| 176 | for sh_file in sorted(TASKS_ROOT.rglob("*.sh")): |
| 177 | content = sh_file.read_text() |
| 178 | |
| 179 | if "WORKSPACE=" not in content: |
| 180 | continue |
| 181 | if "os.environ" not in content: |
| 182 | continue |
| 183 | if "export WORKSPACE" in content: |
| 184 | continue |
| 185 | |
| 186 | task_name = sh_file.parent.parent.name if sh_file.parent.name in ("solution", "environment") else sh_file.parent.name |
| 187 | |
| 188 | # Add export after WORKSPACE= assignment |
| 189 | new_content = re.sub( |
| 190 | r'(WORKSPACE=("[^"]*"|\$\{[^}]*\}|[^\s]*))\n', |
| 191 | r'\1\nexport WORKSPACE\n', |
| 192 | content, |
| 193 | count=1, |
| 194 | ) |
| 195 | |
| 196 | if new_content != content: |
| 197 | stats["export"] += 1 |
| 198 | if apply: |
| 199 | sh_file.write_text(new_content) |
| 200 | print(f" [export] {task_name}: added export WORKSPACE in {sh_file.name}") |
| 201 | |
| 202 | |
| 203 | def fix_fin006_hardcoded(apply: bool): |