Skip to content

Commit

Permalink
Fix-conda-version-parsing (#20674)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Feb 14, 2023
1 parent a6a6f50 commit f3ecbf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/client/pythonEnvironments/common/environmentManagers/conda.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fsapi from 'fs-extra';
import * as path from 'path';
import { lt, parse, SemVer } from 'semver';
import { lt, SemVer } from 'semver';
import { getEnvironmentVariable, getOSType, getUserHomeDir, OSType } from '../../../common/utils/platform';
import {
arePathsSame,
Expand Down Expand Up @@ -552,9 +552,15 @@ export class Conda {
if (!versionString) {
return undefined;
}
const version = parse(versionString, true);
if (version) {
return version;
const pattern = /(?<major>\d+)\.(?<minor>\d+)\.(?<micro>\d+)(?:.*)?/;
const match = versionString.match(pattern);
if (match && match.groups) {
const versionStringParsed = match.groups.major.concat('.', match.groups.minor, '.', match.groups.micro);

const semVarVersion: SemVer = new SemVer(versionStringParsed);
if (semVarVersion) {
return semVarVersion;
}
}
// Use a bogus version, at least to indicate the fact that a version was returned.
// This ensures we still use conda for activation, installation etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,17 @@ suite('Conda and its environments are located correctly', () => {
expect(eq(version!, '4.8.0')).to.equal(true);
});

test('Conda version works for dev versions of conda', async () => {
files = {
conda: JSON.stringify(condaInfo('23.1.0.post7+d5281f611')),
};
condaVersionOutput = 'conda 23.1.0.post7+d5281f611';
const conda = await Conda.getConda();
const version = await conda?.getCondaVersion();
expect(version).to.not.equal(undefined);
expect(eq(version!, '23.1.0')).to.equal(true);
});

test('Conda run args returns `undefined` for conda version below 4.9.0', async () => {
files = {
conda: JSON.stringify(condaInfo('4.8.0')),
Expand Down

0 comments on commit f3ecbf5

Please sign in to comment.