@@ -168,11 +168,7 @@ export const resolveExpectedRuntimeVersion = ({ rootDir }) => {
168168 ) ;
169169} ;
170170
171- export const validateRuntimePython = ( {
172- pythonExecutable,
173- expectedRuntimeConstraint,
174- requirePipProbe,
175- } ) => {
171+ const runPythonProbe = ( { pythonExecutable, requirePipProbe } ) => {
176172 const probeScript = requirePipProbe
177173 ? 'import sys, pip; print(sys.version_info[0], sys.version_info[1])'
178174 : 'import sys; print(sys.version_info[0], sys.version_info[1])' ;
@@ -193,30 +189,46 @@ export const validateRuntimePython = ({
193189
194190 if ( probe . status !== 0 ) {
195191 const stderrText = ( probe . stderr || '' ) . trim ( ) ;
196- if ( requirePipProbe ) {
197- throw new Error (
198- `Runtime Python probe failed with exit code ${ probe . status } . ` +
199- `pip import check is enabled by ASTRBOT_DESKTOP_REQUIRE_PIP=1. ` +
200- ( stderrText ? `stderr: ${ stderrText } ` : '' ) ,
201- ) ;
202- }
203192 throw new Error (
204193 `Runtime Python probe failed with exit code ${ probe . status } . ` +
194+ ( requirePipProbe ? 'pip import check is enabled by ASTRBOT_DESKTOP_REQUIRE_PIP=1. ' : '' ) +
205195 ( stderrText ? `stderr: ${ stderrText } ` : '' ) ,
206196 ) ;
207197 }
208198
209- const parts = ( probe . stdout || '' ) . trim ( ) . split ( / \s + / ) ;
199+ return probe . stdout || '' ;
200+ } ;
201+
202+ const parseProbeVersion = ( stdoutText ) => {
203+ const trimmedOutput = String ( stdoutText || '' ) . trim ( ) ;
204+ const parts = trimmedOutput . split ( / \s + / ) ;
210205 if ( parts . length < 2 ) {
211206 throw new Error (
212- `Runtime Python probe did not report a valid version. Output: ${ ( probe . stdout || '' ) . trim ( ) } ` ,
207+ `Runtime Python probe did not report a valid version. Output: ${ trimmedOutput } ` ,
213208 ) ;
214209 }
215210
216- const actualVersion = {
217- major : Number . parseInt ( parts [ 0 ] , 10 ) ,
218- minor : Number . parseInt ( parts [ 1 ] , 10 ) ,
219- } ;
211+ const major = Number . parseInt ( parts [ 0 ] , 10 ) ;
212+ const minor = Number . parseInt ( parts [ 1 ] , 10 ) ;
213+ if ( ! Number . isInteger ( major ) || ! Number . isInteger ( minor ) ) {
214+ throw new Error (
215+ `Runtime Python probe did not report a valid version. Output: ${ trimmedOutput } ` ,
216+ ) ;
217+ }
218+
219+ return { major, minor } ;
220+ } ;
221+
222+ export const validateRuntimePython = ( {
223+ pythonExecutable,
224+ expectedRuntimeConstraint,
225+ requirePipProbe,
226+ } ) => {
227+ const probeOutput = runPythonProbe ( {
228+ pythonExecutable,
229+ requirePipProbe,
230+ } ) ;
231+ const actualVersion = parseProbeVersion ( probeOutput ) ;
220232 const expectedRuntimeVersion = expectedRuntimeConstraint . expectedRuntimeVersion ;
221233 const compareResult = compareMajorMinor ( actualVersion , expectedRuntimeVersion ) ;
222234 if ( expectedRuntimeConstraint . isLowerBoundRuntimeVersion ) {
0 commit comments