Skip to content

Commit

Permalink
De-duplicate directories at the very end in Global virtual env locato…
Browse files Browse the repository at this point in the history
…rs (#22040)
  • Loading branch information
Kartik Raj authored Sep 21, 2023
1 parent f38ea44 commit 849be34
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { uniq } from 'lodash';
import { toLower, uniq, uniqBy } from 'lodash';
import * as path from 'path';
import { chain, iterable } from '../../../../common/utils/async';
import { getEnvironmentVariable, getOSType, getUserHomeDir, OSType } from '../../../../common/utils/platform';
Expand Down Expand Up @@ -39,19 +39,22 @@ async function getGlobalVirtualEnvDirs(): Promise<string[]> {

const homeDir = getUserHomeDir();
if (homeDir && (await pathExists(homeDir))) {
const subDirs = ['Envs', '.direnv', '.venvs', '.virtualenvs', path.join('.local', 'share', 'virtualenvs')];
if (![OSType.Windows, OSType.OSX].includes(getOSType())) {
// Not a case insensitive platform, push both upper and lower cases.
subDirs.push('envs');
}
const subDirs = [
'envs',
'Envs',
'.direnv',
'.venvs',
'.virtualenvs',
path.join('.local', 'share', 'virtualenvs'),
];
const filtered = await asyncFilter(
subDirs.map((d) => path.join(homeDir, d)),
pathExists,
);
filtered.forEach((d) => venvDirs.push(d));
}

return uniq(venvDirs);
return [OSType.Windows, OSType.OSX].includes(getOSType()) ? uniqBy(venvDirs, toLower) : uniq(venvDirs);
}

/**
Expand Down

0 comments on commit 849be34

Please sign in to comment.