Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
yarn.lock
package-lock.json
platformio-node-helpers-11.3.0.tgz
17 changes: 16 additions & 1 deletion src/installer/get-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ jjxDah2nGN59PRbxYvnKkKj9
-----END CERTIFICATE-----
`;

export async function findPythonExecutable() {
export async function findPythonExecutable(options = {}) {
const maxPythonVersion = options.maxPythonVersion || process.env.PLATFORMIO_MAX_PYTHON_VERSION || '3.13';
const exenames = proc.IS_WINDOWS ? ['python.exe'] : ['python3', 'python'];
const envPath = process.env.PLATFORMIO_PATH || process.env.PATH;
const errors = [];
Expand All @@ -116,6 +117,20 @@ export async function findPythonExecutable() {
fs.existsSync(executable) &&
(await callInstallerScript(executable, ['check', 'python']))
) {
// Verify Python version does not exceed maximum stable baseline
try {
const versionCheck = await proc.getCommandOutput(executable, [
'-c',
`import sys; print("1" if sys.version_info < tuple(map(int, "${maxPythonVersion}".split("."))) else "0")`
]);
if (versionCheck.trim() !== '1') {
console.warn(`Python at ${executable} exceeds max supported version (>= ${maxPythonVersion})`);
continue; // Reject bleeding edge and force fallback loop
}
} catch (err) {
console.warn(`Failed to verify Python version structure for ${executable}:`, err);
continue;
}
return executable;
}
} catch (err) {
Expand Down