"""
HemoStat Platform Detection Utilities
Provides OS detection and platform-specific configuration for Docker socket handling.
Supports Windows, Linux, and macOS with automatic detection of running environment.
"""
import os
import platform
from pathlib import Path
[docs]
def is_in_docker() -> bool:
"""
Detect if the current process is running inside a Docker container.
Returns:
True if running in Docker, False otherwise
"""
return Path("/.dockerenv").exists()
[docs]
def get_docker_host() -> str:
"""
Get the appropriate Docker daemon socket path for the current platform.
Logic:
- If running in Docker container: always use unix:///var/run/docker.sock
(Docker Desktop on Windows maps the named pipe to this path inside containers)
- If running locally on Windows: use npipe:////./pipe/docker_engine
- If running locally on Linux/macOS: use unix:///var/run/docker.sock
Returns:
Docker daemon socket path appropriate for the platform
"""
# Inside Docker containers, always use Unix socket (Docker Desktop handles mapping)
if is_in_docker():
return "unix:///var/run/docker.sock"
# Running locally - check OS
system = get_platform()
if system == "Windows":
return "npipe:////./pipe/docker_engine"
else:
# Linux and macOS both use Unix sockets
return "unix:///var/run/docker.sock"