Skip to content

Commit 170d6bf

Browse files
Don't add code if no environment variables (#255)
## Before <img width="1867" alt="Screenshot 2022-11-28 at 14 38 51" src="https://user-images.githubusercontent.com/88345179/204292549-70892b09-1381-4de6-b37c-732daea8ac02.png"> ## After <img width="2233" alt="Screenshot 2022-11-28 at 14 39 34" src="https://user-images.githubusercontent.com/88345179/204292583-fd24809e-0613-4f03-a903-c78c90acec7c.png">
1 parent 4148c55 commit 170d6bf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/databricks-vscode/src/run/DatabricksRuntime.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe(__filename, () => {
114114
assert(outputs[5].text.includes("Done"));
115115
});
116116

117-
it("should have the right code", async () => {
117+
it("should have the right code with env vars", async () => {
118118
await runtime.start("/Desktop/workspaces/hello.py", [], {TEST: "TEST"});
119119

120120
const code = capture(executionContextMock.execute).first()[0];
@@ -124,6 +124,21 @@ describe(__filename, () => {
124124
import sys; sys.path.append("/Workspace/Repos/[email protected]/test")
125125
import sys; sys.argv = ['/Workspace/Repos/[email protected]/test/hello.py'];
126126
import os; os.environ["TEST"]='TEST';
127+
import logging; logger = spark._jvm.org.apache.log4j; logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
128+
print('43')`
129+
);
130+
});
131+
132+
it("should have the right code without env vars", async () => {
133+
await runtime.start("/Desktop/workspaces/hello.py", [], {});
134+
135+
const code = capture(executionContextMock.execute).first()[0];
136+
assert.equal(
137+
code,
138+
`import os; os.chdir("/Workspace/Repos/[email protected]/test");
139+
import sys; sys.path.append("/Workspace/Repos/[email protected]/test")
140+
import sys; sys.argv = ['/Workspace/Repos/[email protected]/test/hello.py'];
141+
127142
import logging; logger = spark._jvm.org.apache.log4j; logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
128143
print('43')`
129144
);

packages/databricks-vscode/src/run/DatabricksRuntime.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ export class DatabricksRuntime implements Disposable {
274274
.map((arg) => this.escapePythonString(arg))
275275
.join("', '")}'];`,
276276

277-
`import os; ${envVarSetCmds.join("; ")};`,
277+
envVarSetCmds.length !== 0
278+
? `import os; ${envVarSetCmds.join("; ")};`
279+
: "",
278280

279281
// Set log level to "ERROR". See https://kb.databricks.com/notebooks/cmd-c-on-object-id-p0.html
280282
`import logging; logger = spark._jvm.org.apache.log4j; logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)`,

0 commit comments

Comments
 (0)