Skip to content

Commit 9ea7d69

Browse files
committed
jupyter - support paths with special characters. Closes #9133
1 parent 26172cb commit 9ea7d69

File tree

8 files changed

+808
-764
lines changed

8 files changed

+808
-764
lines changed

news/changelog-1.5.md

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ All changes included in 1.5:
6464
- ([#8454](https://github.com/quarto-dev/quarto-cli/issues/8454)): Allow Jupyter engine to handle markdown files with mixed-case extensions.
6565
- ([#8919](https://github.com/quarto-dev/quarto-cli/issues/8919)): Ensure enough backticks in `quarto convert` from `.ipynb` to `.qmd` files.
6666
- ([#8998](https://github.com/quarto-dev/quarto-cli/issues/8998)): Interpret slide separation markers `---` correctly when creating the `.ipynb` intermediate notebook from a `.qmd` file.
67+
- ([#9133](https://github.com/quarto-dev/quarto-cli/issues/9133)): Fix issue with Jupyter engine when using paths containing special characters.
6768

6869
## Website Listings
6970

src/resources/jupyter/lang/julia/setup.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import IJulia
2+
import Base64
23

34
# The julia kernel has built in support for Revise.jl, so this is the
45
# recommended approach for long-running sessions:
@@ -62,8 +63,9 @@ end
6263

6364
# Set run_path if specified
6465
try
65-
run_path = raw"{run_path}"
66+
run_path = "{run_path}"
6667
if !isempty(run_path)
68+
run_path = String(Base64.base64decode(run_path))
6769
cd(run_path)
6870
end
6971
catch e

src/resources/jupyter/lang/python/setup.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import types
66
import json
7+
import base64
78

89
# figure size/format
910
fig_width = {fig_width}
@@ -183,8 +184,11 @@ def patch_theme(*args, **kwargs):
183184
print(json.dumps(kernel_deps))
184185

185186
# set run_path if requested
186-
if r'{run_path}':
187-
os.chdir(r'{run_path}')
187+
run_path = '{run_path}'
188+
if run_path:
189+
# hex-decode the path
190+
run_path = base64.b64decode(run_path.encode("utf-8")).decode("utf-8")
191+
os.chdir(run_path)
188192

189193
# reset state
190194
%reset

src/resources/jupyter/notebook.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import pprint
1010
import copy
11+
import base64
1112

1213
from pathlib import Path
1314

@@ -435,6 +436,8 @@ def nb_language_cell(name, kernelspec, resource_dir, allow_empty, **args):
435436
lang_dir = os.path.join(resource_dir, 'jupyter', 'lang', kernelspec.language)
436437
if os.path.isdir(lang_dir):
437438
cell_file = glob.glob(os.path.join(lang_dir, name + '.*'))
439+
# base64-encode the run_path given
440+
args['run_path'] = base64.b64encode(args.get('run_path', '').encode('utf-8')).decode('utf-8')
438441
if len(cell_file) > 0:
439442
with open(cell_file[0], 'r') as file:
440443
source = file.read().format(**args)

tests/smoke/issues/9133/9133.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { quarto } from "../../../../src/quarto.ts";
2+
import { test } from "../../../test.ts";
3+
if (Deno.build.os !== "windows") {
4+
test({
5+
name: "https://github.com/quarto-dev/quarto-cli/issues/9133",
6+
context: {
7+
setup: async () => {
8+
Deno.mkdir("smoke/issues/9133/oh'\"no", { recursive: true });
9+
Deno.copyFileSync("smoke/issues/9133/jl", "smoke/issues/9133/oh'\"no/jl.qmd");
10+
Deno.copyFileSync("smoke/issues/9133/py", "smoke/issues/9133/oh'\"no/py.qmd");
11+
12+
const timeout = new Promise((_resolve, reject) => {
13+
setTimeout(reject, 600000, "timed out after 10 minutes");
14+
});
15+
await Promise.race([
16+
Promise.all([
17+
quarto(["render", "smoke/issues/9133/oh'\"no/jl.qmd"]),
18+
quarto(["render", "smoke/issues/9133/oh'\"no/py.qmd"]),
19+
]),
20+
timeout,
21+
]);
22+
}
23+
},
24+
execute: async () => {
25+
Deno.removeSync("smoke/issues/9133/oh'\"no", { recursive: true });
26+
},
27+
verify: [],
28+
type: "smoke"
29+
});
30+
}

tests/smoke/issues/9133/jl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: oh oh
3+
engine: jupyter
4+
---
5+
6+
```{julia}
7+
println("Hello world")
8+
```

tests/smoke/issues/9133/py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: oh oh
3+
engine: jupyter
4+
---
5+
6+
```{python}
7+
print("Hello world")
8+
```

0 commit comments

Comments
 (0)