Skip to content

Commit f3ecbf5

Browse files
authored
Fix-conda-version-parsing (#20674)
1 parent a6a6f50 commit f3ecbf5

File tree

2 files changed

+21
-4
lines changed
  • src

2 files changed

+21
-4
lines changed

src/client/pythonEnvironments/common/environmentManagers/conda.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fsapi from 'fs-extra';
22
import * as path from 'path';
3-
import { lt, parse, SemVer } from 'semver';
3+
import { lt, SemVer } from 'semver';
44
import { getEnvironmentVariable, getOSType, getUserHomeDir, OSType } from '../../../common/utils/platform';
55
import {
66
arePathsSame,
@@ -552,9 +552,15 @@ export class Conda {
552552
if (!versionString) {
553553
return undefined;
554554
}
555-
const version = parse(versionString, true);
556-
if (version) {
557-
return version;
555+
const pattern = /(?<major>\d+)\.(?<minor>\d+)\.(?<micro>\d+)(?:.*)?/;
556+
const match = versionString.match(pattern);
557+
if (match && match.groups) {
558+
const versionStringParsed = match.groups.major.concat('.', match.groups.minor, '.', match.groups.micro);
559+
560+
const semVarVersion: SemVer = new SemVer(versionStringParsed);
561+
if (semVarVersion) {
562+
return semVarVersion;
563+
}
558564
}
559565
// Use a bogus version, at least to indicate the fact that a version was returned.
560566
// This ensures we still use conda for activation, installation etc.

src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ suite('Conda and its environments are located correctly', () => {
491491
expect(eq(version!, '4.8.0')).to.equal(true);
492492
});
493493

494+
test('Conda version works for dev versions of conda', async () => {
495+
files = {
496+
conda: JSON.stringify(condaInfo('23.1.0.post7+d5281f611')),
497+
};
498+
condaVersionOutput = 'conda 23.1.0.post7+d5281f611';
499+
const conda = await Conda.getConda();
500+
const version = await conda?.getCondaVersion();
501+
expect(version).to.not.equal(undefined);
502+
expect(eq(version!, '23.1.0')).to.equal(true);
503+
});
504+
494505
test('Conda run args returns `undefined` for conda version below 4.9.0', async () => {
495506
files = {
496507
conda: JSON.stringify(condaInfo('4.8.0')),

0 commit comments

Comments
 (0)