Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-conda-version-parsing #20674

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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