@@ -112,7 +112,8 @@ let releaseCacheTime = 0;
112112const ASSET_NAME_REGEX = / ^ c p y t h o n - ( \d + \. \d + \. \d + ) \+ ( \d + ) - ( [ ^ - ] + ) - ( [ ^ - ] + ) - ( [ ^ - ] + ) (?: - ( [ ^ - ] + ) ) ? (?: - ( [ ^ . ] + ) ) ? \. ( t a r \. (?: g z | z s t ) ) $ / ;
113113
114114/**
115- * Search for existing Python executable in system PATH
115+ * Search for existing Python executable in system PATH with version validation
116+ * Only accepts Python versions 3.10 through 3.13
116117 * @returns {Promise<string|null> } Path to Python executable or null if not found
117118 */
118119export async function findPythonExecutable ( ) {
@@ -125,10 +126,9 @@ export async function findPythonExecutable() {
125126 for ( const exename of exenames ) {
126127 const executable = path . normalize ( path . join ( location , exename ) ) . replace ( / " / g, '' ) ;
127128 try {
128- if (
129- fs . existsSync ( executable ) &&
130- ( await callInstallerScript ( executable , [ 'check' , 'python' ] ) )
131- ) {
129+ if ( fs . existsSync ( executable ) &&
130+ ( await isValidPythonVersion ( executable ) ) &&
131+ ( await callInstallerScript ( executable , [ 'check' , 'python' ] ) ) ) {
132132 return executable ;
133133 }
134134 } catch ( err ) {
@@ -147,6 +147,30 @@ export async function findPythonExecutable() {
147147 return null ;
148148}
149149
150+ /**
151+ * Check if Python executable has acceptable version (3.10-3.13)
152+ * @param {string } executable - Path to Python executable
153+ * @returns {Promise<boolean> } True if version is acceptable
154+ */
155+ async function isValidPythonVersion ( executable ) {
156+ try {
157+ const { execSync } = require ( 'child_process' ) ;
158+ const output = execSync ( `"${ executable } " --version` , {
159+ encoding : 'utf8' ,
160+ timeout : 3000 ,
161+ stdio : [ 'ignore' , 'pipe' , 'pipe' ]
162+ } ) ;
163+
164+ const versionMatch = output . match ( / P y t h o n ( \d + \. \d + \. \d + ) / ) ;
165+ if ( ! versionMatch ) return false ;
166+
167+ const version = versionMatch [ 1 ] ;
168+ return semver . gte ( version , '3.10.0' ) && semver . lt ( version , '3.14.0' ) ;
169+ } catch {
170+ return false ;
171+ }
172+ }
173+
150174/**
151175 * Verify that Python executable exists in the installed directory
152176 * @param {string } pythonDir - Directory containing Python installation
0 commit comments