Skip to content

Commit 7947ec6

Browse files
committed
comments
1 parent de1cae2 commit 7947ec6

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/managers/conda/condaUtils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,19 @@ export async function pickPythonVersion(
757757
);
758758

759759
// Sort versions by major version (descending), ignoring minor/patch for simplicity
760-
const getMajor = (v: string) => parseInt(v.split('.')[0]);
761-
versions = versions.sort((a, b) => getMajor(b) - getMajor(a));
760+
const parseMajorMinor = (v: string) => {
761+
const m = v.match(/^(\d+)(?:\.(\d+))?/);
762+
return { major: m ? Number(m[1]) : 0, minor: m && m[2] ? Number(m[2]) : 0 };
763+
};
764+
765+
versions = versions.sort((a, b) => {
766+
const pa = parseMajorMinor(a);
767+
const pb = parseMajorMinor(b);
768+
if (pa.major !== pb.major) {
769+
return pb.major - pa.major;
770+
} // desc by major
771+
return pb.minor - pa.minor; // desc by minor
772+
});
762773

763774
if (!versions || versions.length === 0) {
764775
versions = ['3.13', '3.12', '3.11', '3.10', '3.9'];

0 commit comments

Comments
 (0)