|
28 | 28 | from pathlib import Path |
29 | 29 | from typing import Set, Optional |
30 | 30 |
|
| 31 | +def _fix_system_path(): |
| 32 | + """Ensure common paths are in PATH, especially on macOS.""" |
| 33 | + extra_paths = [ |
| 34 | + "/usr/local/bin", |
| 35 | + "/opt/homebrew/bin", |
| 36 | + "/opt/local/bin", |
| 37 | + "/usr/bin", |
| 38 | + "/bin", |
| 39 | + "/usr/sbin", |
| 40 | + "/sbin" |
| 41 | + ] |
| 42 | + current_path = os.environ.get("PATH", "").split(os.pathsep) |
| 43 | + path_changed = False |
| 44 | + for p in extra_paths: |
| 45 | + if p not in current_path and os.path.exists(p): |
| 46 | + current_path.append(p) |
| 47 | + path_changed = True |
| 48 | + |
| 49 | + if path_changed: |
| 50 | + os.environ["PATH"] = os.pathsep.join(current_path) |
| 51 | + |
| 52 | +_fix_system_path() |
| 53 | + |
31 | 54 | # Import validation integration |
32 | 55 | try: |
33 | 56 | from bids_validation_integration import ( |
@@ -1434,27 +1457,58 @@ def process_group(common, app, dry_run=False, debug=False): |
1434 | 1457 | run_datalad_command(cmd, cwd=common["bids_folder"], dry_run=dry_run) |
1435 | 1458 |
|
1436 | 1459 | # Build container command |
1437 | | - cmd = ["apptainer", "run"] |
| 1460 | + engine = common.get("container_engine", "apptainer") |
1438 | 1461 |
|
1439 | | - # Add app-specific apptainer arguments |
1440 | | - if app.get("apptainer_args"): |
1441 | | - cmd.extend(sanitize_apptainer_args(app["apptainer_args"])) |
| 1462 | + if engine == "docker": |
| 1463 | + cmd = ["docker", "run", "--rm"] |
| 1464 | + |
| 1465 | + # Apple Silicon support: Add platform flag for standard amd64 containers |
| 1466 | + if platform.system() == "Darwin" and platform.machine() == "arm64": |
| 1467 | + logging.info("Apple Silicon detected. Adding '--platform linux/amd64' for standard container compatibility.") |
| 1468 | + cmd.extend(["--platform", "linux/amd64"]) |
| 1469 | + |
| 1470 | + # Add environment variables |
| 1471 | + cmd.extend(["-e", "TEMPLATEFLOW_HOME=/templateflow"]) |
| 1472 | + |
| 1473 | + # Add bind mounts |
| 1474 | + for mnt in build_common_mounts(common, tmp_dir): |
| 1475 | + cmd.extend(["-v", mnt]) |
| 1476 | + |
| 1477 | + # Add custom mounts |
| 1478 | + for mount in app.get("mounts", []): |
| 1479 | + if mount.get("source") and mount.get("target"): |
| 1480 | + cmd.extend(["-v", f"{mount['source']}:{mount['target']}"]) |
| 1481 | + |
| 1482 | + # Add container image name |
| 1483 | + cmd.append(common["container"]) |
1442 | 1484 | else: |
1443 | | - cmd.append("--containall") |
1444 | | - |
1445 | | - # Add bind mounts |
1446 | | - for mnt in build_common_mounts(common, tmp_dir): |
1447 | | - cmd.extend(["-B", mnt]) |
1448 | | - |
1449 | | - # Add custom mounts |
1450 | | - for mount in app.get("mounts", []): |
1451 | | - if mount.get("source") and mount.get("target"): |
1452 | | - cmd.extend(["-B", f"{mount['source']}:{mount['target']}"]) |
1453 | | - |
1454 | | - # Add environment and container |
| 1485 | + # Default to Apptainer |
| 1486 | + cmd = ["apptainer", "run"] |
| 1487 | + |
| 1488 | + # Add app-specific apptainer arguments (only for apptainer) |
| 1489 | + if app.get("apptainer_args"): |
| 1490 | + safe_args = sanitize_apptainer_args(app["apptainer_args"]) |
| 1491 | + cmd.extend(safe_args) |
| 1492 | + else: |
| 1493 | + cmd.append("--containall") |
| 1494 | + |
| 1495 | + # Add bind mounts |
| 1496 | + for mnt in build_common_mounts(common, tmp_dir): |
| 1497 | + cmd.extend(["-B", mnt]) |
| 1498 | + |
| 1499 | + # Add custom mounts |
| 1500 | + for mount in app.get("mounts", []): |
| 1501 | + if mount.get("source") and mount.get("target"): |
| 1502 | + cmd.extend(["-B", f"{mount['source']}:{mount['target']}"]) |
| 1503 | + |
| 1504 | + # Add environment variables |
| 1505 | + cmd.extend(["--env", "TEMPLATEFLOW_HOME=/templateflow"]) |
| 1506 | + |
| 1507 | + # Add container image path |
| 1508 | + cmd.append(common["container"]) |
| 1509 | + |
| 1510 | + # Add common BIDS app arguments (same for both engines) |
1455 | 1511 | cmd.extend([ |
1456 | | - "--env", f"TEMPLATEFLOW_HOME=/templateflow", |
1457 | | - common["container"], |
1458 | 1512 | "/bids", "/output", app.get("analysis_level", "group"), |
1459 | 1513 | "-w", "/tmp" |
1460 | 1514 | ]) |
|
0 commit comments