Skip to content

Commit 86fc551

Browse files
authored
Improve handling of the %run magic for local runs (#1612)
## Changes - Strip quotes around filenames - Use raw strings for the project root and filename (avoid unicode issues for paths with `\u` sequences - e.g. `\User\***` on Windows) Fixes #1611 ## Tests Existing integ tests
1 parent d533397 commit 86fc551

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/databricks-vscode/resources/python/00-databricks-init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,16 @@ def handle(lines: List[str]):
316316
if len(rest) == 0:
317317
return lines
318318

319-
filename = rest[0]
319+
# Strip whitespace or possible quotes around the filename
320+
filename = rest[0].strip('\'" ')
320321

321322
for suffix in ["", ".py", ".ipynb", ".ipy"]:
322323
if os.path.exists(os.path.join(os.getcwd(), filename + suffix)):
323324
filename = filename + suffix
324325
break
325326

326327
return [
327-
f"with databricks_notebook_exec_env('{cfg.project_root}', '{filename}') as file:\n",
328+
f"with databricks_notebook_exec_env(r'{cfg.project_root}', r'{filename}') as file:\n",
328329
"\t%run -i {file} " + lines[0].partition('%run')[2].partition(filename)[2] + "\n"
329330
]
330331

0 commit comments

Comments
 (0)