Skip to content

Commit

Permalink
Merge pull request #9239 from quarto-dev/bugfix/apostrophe-in-jupyter…
Browse files Browse the repository at this point in the history
…-path

Bugfix/apostrophe in jupyter path
  • Loading branch information
cscheid authored Apr 2, 2024
2 parents 7be6dd5 + b2af1ad commit f1441f7
Show file tree
Hide file tree
Showing 8 changed files with 808 additions and 764 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ All changes included in 1.5:
- ([#8454](https://github.com/quarto-dev/quarto-cli/issues/8454)): Allow Jupyter engine to handle markdown files with mixed-case extensions.
- ([#8919](https://github.com/quarto-dev/quarto-cli/issues/8919)): Ensure enough backticks in `quarto convert` from `.ipynb` to `.qmd` files.
- ([#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.
- ([#9133](https://github.com/quarto-dev/quarto-cli/issues/9133)): Fix issue with Jupyter engine when using paths containing special characters.

## Website Listings

Expand Down
4 changes: 3 additions & 1 deletion src/resources/jupyter/lang/julia/setup.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import IJulia
import Base64

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

# Set run_path if specified
try
run_path = raw"{run_path}"
run_path = "{run_path}"
if !isempty(run_path)
run_path = String(Base64.base64decode(run_path))
cd(run_path)
end
catch e
Expand Down
8 changes: 6 additions & 2 deletions src/resources/jupyter/lang/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import types
import json
import base64

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

# set run_path if requested
if r'{run_path}':
os.chdir(r'{run_path}')
run_path = '{run_path}'
if run_path:
# hex-decode the path
run_path = base64.b64decode(run_path.encode("utf-8")).decode("utf-8")
os.chdir(run_path)

# reset state
%reset
Expand Down
3 changes: 3 additions & 0 deletions src/resources/jupyter/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import pprint
import copy
import base64

from pathlib import Path

Expand Down Expand Up @@ -435,6 +436,8 @@ def nb_language_cell(name, kernelspec, resource_dir, allow_empty, **args):
lang_dir = os.path.join(resource_dir, 'jupyter', 'lang', kernelspec.language)
if os.path.isdir(lang_dir):
cell_file = glob.glob(os.path.join(lang_dir, name + '.*'))
# base64-encode the run_path given
args['run_path'] = base64.b64encode(args.get('run_path', '').encode('utf-8')).decode('utf-8')
if len(cell_file) > 0:
with open(cell_file[0], 'r') as file:
source = file.read().format(**args)
Expand Down
30 changes: 30 additions & 0 deletions tests/smoke/issues/9133/9133.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { quarto } from "../../../../src/quarto.ts";
import { test } from "../../../test.ts";
if (Deno.build.os !== "windows") {
test({
name: "https://github.com/quarto-dev/quarto-cli/issues/9133",
context: {
setup: async () => {
Deno.mkdirSync("smoke/issues/9133/oh'\"no", { recursive: true });
Deno.copyFileSync("smoke/issues/9133/jl", "smoke/issues/9133/oh'\"no/jl.qmd");
Deno.copyFileSync("smoke/issues/9133/py", "smoke/issues/9133/oh'\"no/py.qmd");

const timeout = new Promise((_resolve, reject) => {
setTimeout(reject, 600000, "timed out after 10 minutes");
});
await Promise.race([
Promise.all([
quarto(["render", "smoke/issues/9133/oh'\"no/jl.qmd"]),
quarto(["render", "smoke/issues/9133/oh'\"no/py.qmd"]),
]),
timeout,
]);
}
},
execute: async () => {
Deno.removeSync("smoke/issues/9133/oh'\"no", { recursive: true });
},
verify: [],
type: "smoke"
});
}
8 changes: 8 additions & 0 deletions tests/smoke/issues/9133/jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: oh oh
engine: jupyter
---

```{julia}
println("Hello world")
```
8 changes: 8 additions & 0 deletions tests/smoke/issues/9133/py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: oh oh
engine: jupyter
---

```{python}
print("Hello world")
```
Loading

0 comments on commit f1441f7

Please sign in to comment.