MCPcopy Create free account
hub / github.com/FastLED/FastLED / _check_wsl2_docker_backend

Function _check_wsl2_docker_backend

ci/util/docker_helper.py:66–139  ·  view source on GitHub ↗

Check if Docker's WSL2 backend is running on Windows. Returns: Tuple of (is_running, diagnostic_message) - is_running: True if docker-desktop WSL2 distribution is running - diagnostic_message: Information about WSL2 status

()

Source from the content-addressed store, hash-verified

64
65
66def _check_wsl2_docker_backend() -> tuple[bool, str]:
67 """Check if Docker's WSL2 backend is running on Windows.
68
69 Returns:
70 Tuple of (is_running, diagnostic_message)
71 - is_running: True if docker-desktop WSL2 distribution is running
72 - diagnostic_message: Information about WSL2 status
73 """
74 try:
75 # Check if WSL is available
76 result = subprocess.run(
77 ["wsl", "--list", "--verbose"],
78 capture_output=True,
79 text=True,
80 timeout=10,
81 )
82
83 if result.returncode != 0:
84 return False, "WSL2 not available or not configured"
85
86 output = result.stdout
87
88 # Handle WSL output encoding issues (spaces between characters in Git Bash)
89 # Clean up the output by removing extra spaces
90 cleaned_lines: list[str] = []
91 for line in output.split("\n"):
92 # Remove null bytes and collapse multiple spaces
93 cleaned = line.replace("\x00", "").strip()
94 # If line has pattern like "d o c k e r", remove spaces between single chars
95 if " " in cleaned and len([c for c in cleaned.split() if len(c) == 1]) > 3:
96 # This line has spaced-out characters - remove spaces
97 cleaned = cleaned.replace(" ", "")
98 cleaned_lines.append(cleaned)
99
100 # Look for docker-desktop distribution
101 for line in cleaned_lines:
102 line_lower = line.lower()
103 if "docker-desktop" in line_lower or "dockerdesktop" in line_lower:
104 # Parse WSL status line (format: " * docker-desktop Running 2")
105 # After cleaning: "docker-desktopStopped2" or "docker-desktop Running 2"
106 parts = line.split()
107
108 # Check if line contains status keywords
109 if "running" in line_lower:
110 return True, "docker-desktop WSL2 backend is running"
111 elif "stopped" in line_lower:
112 return False, "docker-desktop WSL2 backend is stopped"
113 else:
114 # Try to extract status from parts
115 if len(parts) >= 2:
116 status = parts[-2] if len(parts) >= 3 else parts[-1]
117 if status.lower() == "running":
118 return True, "docker-desktop WSL2 backend is running"
119 elif status.lower() == "stopped":
120 return False, "docker-desktop WSL2 backend is stopped"
121 else:
122 return (
123 False,

Callers 2

_start_docker_windowsFunction · 0.85

Calls 3

runMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected