Skip to content

Commit cf3eda9

Browse files
committed
sort by version (desc) in conda create picker
1 parent d4bd757 commit cf3eda9

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/managers/conda/condaUtils.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { Common, CondaStrings, PackageManagement, Pickers } from '../../common/l
3131
import { traceInfo, traceVerbose } from '../../common/logging';
3232
import { getWorkspacePersistentState } from '../../common/persistentState';
3333
import { pickProject } from '../../common/pickers/projects';
34+
import { StopWatch } from '../../common/stopWatch';
3435
import { createDeferred } from '../../common/utils/deferred';
3536
import { untildify } from '../../common/utils/pathUtils';
3637
import { isWindows } from '../../common/utils/platformUtils';
@@ -56,7 +57,6 @@ import { Installable } from '../common/types';
5657
import { shortVersion, sortEnvironments } from '../common/utils';
5758
import { CondaEnvManager } from './condaEnvManager';
5859
import { getCondaHookPs1Path, getLocalActivationScript } from './condaSourcingUtils';
59-
import { StopWatch } from '../../common/stopWatch';
6060

6161
export const CONDA_PATH_KEY = `${ENVS_EXTENSION_ID}:conda:CONDA_PATH`;
6262
export const CONDA_PREFIXES_KEY = `${ENVS_EXTENSION_ID}:conda:CONDA_PREFIXES`;
@@ -742,7 +742,6 @@ function trimVersionToMajorMinor(version: string): string {
742742
const match = version.match(/^(\d+\.\d+\.\d+)/);
743743
return match ? match[1] : version;
744744
}
745-
746745
export async function pickPythonVersion(
747746
api: PythonEnvironmentApi,
748747
token?: CancellationToken,
@@ -755,11 +754,16 @@ export async function pickPythonVersion(
755754
.filter(Boolean)
756755
.map((v) => trimVersionToMajorMinor(v)), // cut to 3 digits
757756
),
758-
)
759-
.sort()
760-
.reverse();
761-
if (!versions) {
762-
versions = ['3.11', '3.10', '3.9', '3.12', '3.13'];
757+
);
758+
759+
// Sort versions by major version (descending), ignoring minor/patch for simplicity
760+
versions = versions.sort((a, b) => {
761+
const getMajor = (v: string) => parseInt(v.split('.')[0], 10);
762+
return getMajor(b) - getMajor(a);
763+
});
764+
765+
if (!versions || versions.length === 0) {
766+
versions = ['3.13', '3.12', '3.11', '3.10', '3.9'];
763767
}
764768
const items: QuickPickItem[] = versions.map((v) => ({
765769
label: v === RECOMMENDED_CONDA_PYTHON ? `$(star-full) Python` : 'Python',

0 commit comments

Comments
 (0)