Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit c9adf73

Browse files
committed
Use correct file extension for script output
1 parent eee4d8c commit c9adf73

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/jupyter_notebook_gist/handlers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,23 @@ def get(self):
7272
filename, filename_no_ext = get_notebook_filename(nb_path)
7373

7474
# Extract file contents given the path to the notebook
75-
notebook_output, python_output = get_notebook_contents(nb_path)
75+
notebook_output, script_output, ext = get_notebook_contents(nb_path)
7676

7777
# Prepare and our github request to create the new gist
78-
filename_with_py = filename_no_ext + ".py"
78+
filename_with_ext = filename_no_ext + ext
7979
gist_contents = {
8080
"description": filename_no_ext,
8181
"public": False,
8282
"files": {
8383
filename: {"filename": filename, "content": notebook_output},
84-
filename_with_py: {"filename": filename_with_py,
85-
"content": python_output}
84+
filename_with_ext: {"filename": filename_with_ext,
85+
"content": script_output}
8686
}
8787
}
8888

8989
# Get the authenticated user's matching gist (if available)
9090
match_id = find_existing_gist_by_name(filename,
91-
filename_with_py,
91+
filename_with_ext,
9292
access_token)
9393

9494
# If no gist with this name exists yet, create a new gist
@@ -257,11 +257,12 @@ def get_notebook_contents(nb_path):
257257
# Extract file contents given the path to the notebook
258258
try:
259259
notebook_output, _ = export_by_name("notebook", nb_path)
260-
python_output, _ = export_by_name("python", nb_path)
260+
script_output, script_resources = export_by_name("script", nb_path)
261+
261262
except OSError: # python 2 does not support FileNotFoundError
262263
raise_error("Couldn't export notebook contents")
263264

264-
return (notebook_output, python_output)
265+
return (notebook_output, script_output, script_resources['output_extension'])
265266

266267

267268
def find_existing_gist_by_name(nb_filename, py_filename, access_token):

tests/test_handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ def test_get_notebook_contents_notebook(self):
334334
encoding='utf-8') as f:
335335
write(nb, f, version=4)
336336

337-
nb_content, python_content = get_notebook_contents(fname)
337+
nb_content, python_content, ext = get_notebook_contents(fname)
338338
self.assertTrue(len(nb_content) > 0)
339339
self.assertTrue(len(python_content) > 0)
340+
assert ext == ".py"
340341

341342
# Delete the temporary file
342343
os.remove(nbdir + "/" + fname)

0 commit comments

Comments
 (0)