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

add cwd for debugging #21668

Merged
merged 7 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 18 additions & 2 deletions src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,24 @@ export class DebugLauncher implements ITestDebugLauncher {
`Missing value for debug setup, both port and uuid need to be defined. port: "${options.pytestPort}" uuid: "${options.pytestUUID}"`,
);
}
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
launchArgs.env.PYTHONPATH = pluginPath;
}
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
// check if PYTHONPATH is already set in the environment variables
if (launchArgs.env && launchArgs.env.PYTHONPATH) {
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
// add the plugin path or cwd to PYTHONPATH if it is not already there
if (!launchArgs.env.PYTHONPATH.includes(pluginPath)) {
launchArgs.env.PYTHONPATH = `${launchArgs.env.PYTHONPATH}${path.delimiter}${pluginPath}`;
}
if (launchArgs.cwd) {
if (!launchArgs.env.PYTHONPATH.includes(launchArgs.cwd)) {
launchArgs.env.PYTHONPATH = `${launchArgs.env.PYTHONPATH}${path.delimiter}${launchArgs.cwd}`;
}
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
} else if (!launchArgs.env.PYTHONPATH.includes(options.cwd)) {
launchArgs.env.PYTHONPATH = `${launchArgs.env.PYTHONPATH}${path.delimiter}${options.cwd}`;
}
} else if (launchArgs.env) {
// if PYTHONPATH is not set in the environment variables, set it to the plugin path and cwd
launchArgs.env.PYTHONPATH = `${pluginPath}${path.delimiter}${options.cwd}`;
}

// Clear out purpose so we can detect if the configuration was used to
Expand Down
8 changes: 8 additions & 0 deletions src/test/testing/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ suite('Unit Tests - Debug Launcher', () => {
if (!expected.cwd) {
expected.cwd = workspaceFolders[0].uri.fsPath;
}
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
const pythonPath = `${pluginPath}${path.delimiter}${expected.cwd}`;
expected.env.PYTHONPATH = pythonPath;

// added by LaunchConfigurationResolver:
if (!expected.python) {
Expand Down Expand Up @@ -342,6 +345,10 @@ suite('Unit Tests - Debug Launcher', () => {
};
const expected = getDefaultDebugConfig();
expected.cwd = 'path/to/settings/cwd';
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
const pythonPath = `${pluginPath}${path.delimiter}${expected.cwd}`;
expected.env.PYTHONPATH = pythonPath;

setupSuccess(options, 'unittest', expected);
await debugLauncher.launchDebugger(options);

Expand All @@ -366,6 +373,7 @@ suite('Unit Tests - Debug Launcher', () => {
console: 'integratedTerminal',
cwd: 'some/dir',
env: {
PYTHONPATH: 'one/two/three',
SPAM: 'EGGS',
},
envFile: 'some/dir/.env',
Expand Down