Skip to content

macOS Platform

macos

macOS-specific platform implementation.

Handles symlinks, Python detection (Homebrew, pyenv), and admin checks. Long path support is a no-op (macOS has no 260-char limit).

MacOSPlatform

Bases: Platform

macOS platform implementation.

is_admin()

Check if running as root.

Source code in src/platform/macos.py
def is_admin(self) -> bool:
    """Check if running as root."""
    return os.getuid() == 0

enable_long_paths(log=None)

No-op on macOS — long paths are always supported.

Source code in src/platform/macos.py
def enable_long_paths(self, log: InstallerLogger | None = None) -> bool:
    """No-op on macOS — long paths are always supported."""
    if log is None:
        log = get_logger()
    log.sub("Long path support: native (no action needed).", style="success")
    return True

detect_python(version='3.13', log=None)

Detect a specific Python version on macOS.

Checks: 1. Homebrew paths (/opt/homebrew/bin/python3.x, /usr/local/bin/python3.x) 2. Versioned binary in PATH (python3.13) 3. python3 binary in PATH

Parameters:

Name Type Description Default
version str

The version to look for (e.g. "3.13").

'3.13'
log InstallerLogger | None

Optional logger instance.

None

Returns:

Type Description
Path | None

Path to python executable, or None.

Source code in src/platform/macos.py
def detect_python(self, version: str = "3.13", log: InstallerLogger | None = None) -> Path | None:
    """
    Detect a specific Python version on macOS.

    Checks:
    1. Homebrew paths (/opt/homebrew/bin/python3.x, /usr/local/bin/python3.x)
    2. Versioned binary in PATH (python3.13)
    3. python3 binary in PATH

    Args:
        version: The version to look for (e.g. "3.13").
        log: Optional logger instance.

    Returns:
        Path to python executable, or None.
    """
    if log is None:
        log = get_logger()

    # 1. Try Homebrew explicitly
    brew_paths = [
        Path(f"/opt/homebrew/bin/python{version}"),
        Path(f"/usr/local/bin/python{version}"),
        Path.home() / f".pyenv/shims/python{version}",
    ]
    for candidate in brew_paths:
        if candidate.exists() and os.access(candidate, os.X_OK):
            log.sub(f"Python {version} found: {candidate}", style="success")
            return candidate

    # 2. Try version-specific binary in PATH (e.g. python3.13)
    versioned = shutil.which(f"python{version}")
    if versioned:
        log.sub(f"Python {version} found: {versioned}", style="success")
        return Path(versioned)

    # 3. Try python3 and check version
    for candidate_name in ("python3", "python"):
        candidate_path = shutil.which(candidate_name)
        if candidate_path:
            try:
                result = subprocess.run(
                    [candidate_path, "--version"],
                    capture_output=True,
                    text=True,
                    timeout=10,
                )
                if result.returncode == 0 and f"Python {version}" in result.stdout:
                    log.sub(f"Python {version} found: {candidate_path}", style="success")
                    return Path(candidate_path)
            except (subprocess.TimeoutExpired, OSError):
                pass

    return None

get_app_data_dir()

Get the macOS application support directory.

Source code in src/platform/macos.py
def get_app_data_dir(self) -> Path:
    """Get the macOS application support directory."""
    return Path.home() / "Library" / "Application Support" / "UmeAiRT"