Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ async function isLocalPoetryEnvironment(interpreterPath: string): Promise<boolea
// - 'pyproject.toml' has a poetry section which contains the necessary fields
// - Poetry configuration allows local virtual environments
// ... possibly more
// Or we can simply try running poetry to find the related environment instead. We do the latter for simplicity and reliability.
// It should not be much expensive as we have already narrowed down this possibility through various file checks.
return isPoetryEnvironmentRelatedToFolder(interpreterPath, project);
// Or we can try running poetry to find the related environment instead. Launching poetry binaries although
// reliable, can be expensive. So report the best effort type instead, i.e this is likely a poetry env.
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tool.poetrzzzzy]
name = "poetry-tutorial-project"
version = "0.1.0"
description = ""

[tool.poetry.dependencies]
python = "^3.5"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';

const testPoetryDir = path.join(TEST_LAYOUT_ROOT, 'poetry');
const project1 = path.join(testPoetryDir, 'project1');
const project2 = path.join(testPoetryDir, 'project2');
const project4 = path.join(testPoetryDir, 'project4');
const project3 = path.join(testPoetryDir, 'project3');

suite('isPoetryEnvironment Tests', () => {
Expand Down Expand Up @@ -54,17 +54,9 @@ suite('isPoetryEnvironment Tests', () => {
shellExecute = sinon.stub(externalDependencies, 'shellExecute');
getPythonSetting = sinon.stub(externalDependencies, 'getPythonSetting');
getPythonSetting.returns('poetry');
shellExecute.callsFake((command: string, options: ShellOptions) => {
// eslint-disable-next-line default-case
switch (command) {
case 'poetry env list --full-path':
return Promise.resolve<ExecutionResult<string>>({ stdout: '' });
case 'poetry env info -p':
if (options.cwd && externalDependencies.arePathsSame(options.cwd, project1)) {
return Promise.resolve<ExecutionResult<string>>({
stdout: `${path.join(project1, '.venv')} \n`,
});
}
shellExecute.callsFake((command: string, _options: ShellOptions) => {
if (command === 'poetry env list --full-path') {
return Promise.resolve<ExecutionResult<string>>({ stdout: '' });
}
return Promise.reject(new Error('Command failed'));
});
Expand All @@ -84,8 +76,8 @@ suite('isPoetryEnvironment Tests', () => {
expect(result).to.equal(false);
});

test(`Return false if running poetry for project dir as cwd fails`, async () => {
const result = await isPoetryEnvironment(path.join(project2, '.venv', 'bin', 'python'));
test(`Return false if running poetry for project dir as cwd fails (pyproject.toml file is invalid)`, async () => {
const result = await isPoetryEnvironment(path.join(project4, '.venv', 'bin', 'python'));
expect(result).to.equal(false);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ suite('Poetry Locator', () => {
locator = new PoetryLocator(project1);
getOSTypeStub.returns(platformUtils.OSType.Windows);
shellExecute.callsFake((command: string, options: ShellOptions) => {
if (command === 'poetry env info -p') {
if (options.cwd && externalDependencies.arePathsSame(options.cwd, project1)) {
return Promise.resolve<ExecutionResult<string>>({
stdout: `${path.join(project1, '.venv')} \n`,
});
}
} else if (command === 'poetry env list --full-path') {
if (command === 'poetry env list --full-path') {
if (options.cwd && externalDependencies.arePathsSame(options.cwd, project1)) {
return Promise.resolve<ExecutionResult<string>>({
stdout: `${path.join(testPoetryDir, 'poetry-tutorial-project-6hnqYwvD-py3.8')} \n
Expand Down Expand Up @@ -214,14 +208,7 @@ suite('Poetry Locator', () => {
locator = new PoetryLocator(project2);
getOSTypeStub.returns(platformUtils.OSType.Linux);
shellExecute.callsFake((command: string, options: ShellOptions) => {
// eslint-disable-next-line default-case
if (command === 'poetry env info -p') {
if (options.cwd && externalDependencies.arePathsSame(options.cwd, project2)) {
return Promise.resolve<ExecutionResult<string>>({
stdout: `${path.join(project2, '.venv')} \n`,
});
}
} else if (command === 'poetry env list --full-path') {
if (command === 'poetry env list --full-path') {
if (options.cwd && externalDependencies.arePathsSame(options.cwd, project2)) {
return Promise.resolve<ExecutionResult<string>>({
stdout: `${path.join(testPoetryDir, 'posix1project-9hvDnqYw-py3.4')} (Activated)\n
Expand Down