55 ExtensionContext ,
66} from "vscode" ;
77import path from "node:path" ;
8+ import { DatabricksEnvFileManager } from "../file-managers/DatabricksEnvFileManager" ;
89
910export interface DatabricksPythonDebugConfiguration extends DebugConfiguration {
1011 databricks ?: boolean ;
@@ -14,27 +15,50 @@ export interface DatabricksPythonDebugConfiguration extends DebugConfiguration {
1415 console ?: "integratedTerminal" | "externalTerminal" | "internalConsole" ;
1516}
1617
18+ function isTest ( debugConfiguration : DebugConfiguration ) {
19+ return (
20+ debugConfiguration . env ?. RUN_TEST_IDS_PORT !== undefined ||
21+ debugConfiguration . request === "test" ||
22+ debugConfiguration . name === "Debug Unit Test"
23+ ) ;
24+ }
1725export class DatabricksDebugConfigurationProvider
1826 implements DebugConfigurationProvider
1927{
20- constructor ( private readonly context : ExtensionContext ) { }
28+ constructor (
29+ private readonly context : ExtensionContext ,
30+ private readonly databricksEnvFileManager : DatabricksEnvFileManager
31+ ) { }
32+
2133 async resolveDebugConfigurationWithSubstitutedVariables (
2234 folder : WorkspaceFolder | undefined ,
2335 debugConfiguration : DebugConfiguration
2436 ) {
25- if ( debugConfiguration . databricks !== true ) {
37+ if (
38+ debugConfiguration . databricks !== true &&
39+ ! isTest ( debugConfiguration )
40+ ) {
2641 return debugConfiguration ;
2742 }
2843
29- const userProgram = debugConfiguration . program ;
30- debugConfiguration . program = this . context . asAbsolutePath (
31- path . join ( "resources" , "python" , "dbconnect-bootstrap.py" )
32- ) ;
44+ // Only add the bootstrap script if we are running explicit databricks debug
45+ // configs. Other sources of configs such as tests, should not have the bootstrap
46+ if ( debugConfiguration . databricks ) {
47+ const userProgram = debugConfiguration . program ;
48+ debugConfiguration . program = this . context . asAbsolutePath (
49+ path . join ( "resources" , "python" , "dbconnect-bootstrap.py" )
50+ ) ;
51+ debugConfiguration . args = [
52+ userProgram ,
53+ ...( debugConfiguration . args ?? [ ] ) ,
54+ ] ;
55+ }
3356
34- debugConfiguration . args = [
35- userProgram ,
36- ...( debugConfiguration . args ?? [ ] ) ,
37- ] ;
57+ // Explicitly set our env vars even though bootstrap loads them.
58+ debugConfiguration . env = {
59+ ...( await this . databricksEnvFileManager . getEnv ( ) ) ,
60+ ...( debugConfiguration . env ?? { } ) ,
61+ } ;
3862
3963 return debugConfiguration ;
4064 }
0 commit comments