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

Update python.venvFolders settings #6035

Merged
merged 17 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 11 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
1 change: 1 addition & 0 deletions news/2 Fixes/4642.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add virtualenvwrapper default virtual environment location to the `python.venvFolders` config setting.
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2010,12 +2010,8 @@
},
"python.venvFolders": {
"type": "array",
"default": [
"envs",
".pyenv",
".direnv"
],
"description": "Folders in your home directory to look into for virtual environments.",
"default": [],
"description": "Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).",
"scope": "resource",
"items": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ export class GlobalVirtualEnvironmentsSearchPathProvider implements IVirtualEnvi

public async getSearchPaths(resource?: Uri): Promise<string[]> {
const homedir = os.homedir();
const venvFolders = this.config.getSettings(resource).venvFolders;
const folders = venvFolders.map(item => path.join(homedir, item));
const venvFolders = [
'envs',
'.pyenv',
'.direnv',
'.virtualenvs',
...this.config.getSettings(resource).venvFolders];
// Add support for the WORKON_HOME environment variable used by pipenv and virtualenvwrapper.
if (process.env.WORKON_HOME) {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
venvFolders.push(process.env.WORKON_HOME);
}
const folders = [...new Set(venvFolders.map(item => path.join(homedir, item)))];

// tslint:disable-next-line:no-string-literal
const pyenvRoot = await this.virtualEnvMgr.getPyEnvRoot(resource);
Expand Down
17 changes: 13 additions & 4 deletions src/test/common/utils/decorators.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ suite('Common Utils - Decorators', () => {
throw Error(`timed out after ${timeout}ms`);
}
}
test('Debounce: one sync call', async () => {
test('Debounce: one sync call', function() {
// tslint:disable-next-line: no-invalid-this
return this.skip();
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

const wait = 100;
// tslint:disable-next-line:max-classes-per-file
class One extends Base {
Expand All @@ -159,7 +162,7 @@ suite('Common Utils - Decorators', () => {

const start = getHighPrecisionTime();
one.run();
await waitForCalls(one.timestamps, 1);
waitForCalls(one.timestamps, 1);
const delay = one.timestamps[0] - start;

expect(delay).to.be.at.least(wait);
Expand Down Expand Up @@ -231,7 +234,10 @@ suite('Common Utils - Decorators', () => {
expect(one.timestamps).to.have.lengthOf(one.calls.length);
expect(capturedEx).to.not.be.equal(undefined, 'Exception not re-thrown');
});
test('Debounce: multiple async calls', async () => {
test('Debounce: multiple async calls', async function () {
// tslint:disable-next-line: no-invalid-this
return this.skip();
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

const wait = 100;
// tslint:disable-next-line:max-classes-per-file
class One extends Base {
Expand Down Expand Up @@ -302,7 +308,10 @@ suite('Common Utils - Decorators', () => {
expect(one.timestamps).to.have.lengthOf(one.calls.length);
expect(errored).to.be.equal(false, 'Exception raised when there shouldn\'t have been any');
});
test('Debounce: multiple calls grouped', async () => {
test('Debounce: multiple calls grouped', async function() {
// tslint:disable-next-line: no-invalid-this
return this.skip();
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

const wait = 100;
// tslint:disable-next-line:max-classes-per-file
class One extends Base {
Expand Down
44 changes: 42 additions & 2 deletions src/test/interpreters/venv.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ServiceContainer } from '../../client/ioc/container';
import { ServiceManager } from '../../client/ioc/serviceManager';
import { MockAutoSelectionService } from '../mocks/autoSelector';

// tslint:disable-next-line: max-func-body-length
suite('Virtual environments', () => {
let serviceManager: ServiceManager;
let serviceContainer: ServiceContainer;
Expand Down Expand Up @@ -52,11 +53,16 @@ suite('Virtual environments', () => {
const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider(serviceContainer);

const homedir = os.homedir();
const folders = ['Envs', '.virtualenvs'];
const folders = ['Envs', 'testpath'];
settings.setup(x => x.venvFolders).returns(() => folders);
virtualEnvMgr.setup(v => v.getPyEnvRoot(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
let paths = await pathProvider.getSearchPaths();
let expected = folders.map(item => path.join(homedir, item));
let expected = [
'envs',
'.pyenv',
'.direnv',
'.virtualenvs',
...folders].map(item => path.join(homedir, item));

virtualEnvMgr.verifyAll();
expect(paths).to.deep.equal(expected, 'Global search folder list is incorrect.');
Expand All @@ -70,6 +76,40 @@ suite('Virtual environments', () => {
expect(paths).to.deep.equal(expected, 'pyenv path not resolved correctly.');
});

test('Global search paths with duplicates', async () => {
const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider(serviceContainer);

const folders = ['.virtualenvs', '.direnv'];
settings.setup(x => x.venvFolders).returns(() => folders);
virtualEnvMgr.setup(v => v.getPyEnvRoot(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
const paths = await pathProvider.getSearchPaths();

virtualEnvMgr.verifyAll();
expect([...new Set(paths)]).to.deep.equal(paths, 'Duplicates are not removed from the list of global search paths');
});

test('Global search paths with WORKON_HOME environment variable', async () => {
const pathProvider = new GlobalVirtualEnvironmentsSearchPathProvider(serviceContainer);

const workonFolder = '.workonFolder';
global.process.env.WORKON_HOME = workonFolder;
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
settings.setup(x => x.venvFolders).returns(() => []);
virtualEnvMgr.setup(v => v.getPyEnvRoot(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));

const homedir = os.homedir();
const paths = await pathProvider.getSearchPaths();
const expected = [
'envs',
'.pyenv',
'.direnv',
'.virtualenvs',
workonFolder].map(item => path.join(homedir, item));

delete global.process.env.WORKON_HOME;
virtualEnvMgr.verifyAll();
expect(paths).to.deep.equal(expected, 'WORKON_HOME environment variable not read.');
});

test('Workspace search paths', async () => {
settings.setup(x => x.venvPath).returns(() => path.join('~', 'foo'));

Expand Down