MCPcopy Index your code
hub / github.com/AutoForgeAI/autoforge / findPython

Function findPython

lib/cli.js:134–197  ·  view source on GitHub ↗

* Find a suitable Python >= 3.11 interpreter. * * Search order is platform-dependent: * Windows: python -> py -3 -> python3 * macOS/Linux: python3 -> python * * The AUTOFORGE_PYTHON env var overrides automatic detection. * * After finding a candidate we also verify that the venv modu

()

Source from the content-addressed store, hash-verified

132 * available (Debian/Ubuntu strip it out of the base package).
133 */
134function findPython() {
135 // Allow explicit override via environment variable
136 const override = process.env.AUTOFORGE_PYTHON;
137 if (override) {
138 const result = tryPythonCandidate(override);
139 if (!result) {
140 die(`AUTOFORGE_PYTHON is set to "${override}" but it could not be executed.`);
141 }
142 if (result.tooOld) {
143 die(
144 `Python ${result.version.raw} found (via AUTOFORGE_PYTHON), but 3.11+ required.\n` +
145 ' Install Python 3.11+ from https://python.org'
146 );
147 }
148 return result;
149 }
150
151 // Platform-specific candidate order
152 const candidates = IS_WIN
153 ? ['python', ['py', '-3'], 'python3']
154 : ['python3', 'python'];
155
156 let bestTooOld = null;
157
158 for (const candidate of candidates) {
159 const result = tryPythonCandidate(candidate);
160 if (!result) continue;
161
162 if (result.tooOld) {
163 // Remember the first "too old" result for a better error message
164 if (!bestTooOld) bestTooOld = result;
165 continue;
166 }
167
168 // Verify venv module is available (Debian/Ubuntu may need python3-venv)
169 try {
170 const exeParts = result.exe.split(' ');
171 execFileSync(exeParts[0], [...exeParts.slice(1), '-c', 'import ensurepip'], {
172 encoding: 'utf8',
173 timeout: 10_000,
174 stdio: ['pipe', 'pipe', 'pipe'],
175 });
176 } catch {
177 die(
178 `Python venv module not available.\n` +
179 ` Run: sudo apt install python3.${result.version.minor}-venv`
180 );
181 }
182
183 return result;
184 }
185
186 // Provide the most helpful error message we can
187 if (bestTooOld) {
188 die(
189 `Python ${bestTooOld.version.raw} found, but 3.11+ required.\n` +
190 ' Install Python 3.11+ from https://python.org'
191 );

Callers 1

startServerFunction · 0.85

Calls 2

tryPythonCandidateFunction · 0.85
dieFunction · 0.85

Tested by

no test coverage detected