Skip to content

Commit

Permalink
regis and kirsty comments
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Regeard <regeard@apc.in2p3.fr>
  • Loading branch information
MRegeard committed Oct 26, 2023
1 parent fed9a06 commit ec2f774
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dev/ipynb_to_gallery.py
@@ -1,9 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
This python script is inspired from https://gist.github.com/chsasank/7218ca16f8d022e02a9c0deb94a310fe .
This python script is inspired by https://gist.github.com/chsasank/7218ca16f8d022e02a9c0deb94a310fe .
Convert jupyter notebook to sphinx gallery python script.
Usage: python ipynb_to_gallery.py <notebook.ipynb> (Optional)<output.py>
Usage: python ipynb_to_gallery.py notebook.ipynb (Optional)script.py
"""
import json
import pypandoc as pdoc
Expand All @@ -13,12 +14,13 @@ def convert_ipynb_to_gallery(input_file_name, output_file_name=None):
"""
Convert jupyter notebook to sphinx gallery python script.
parameters
Parameters
----------
input_file_name: str
Path to the jupyter notebook file.
output_file_name: str
Path to the output python file. If not provided, the output file name is the same as the input file name.
output_file_name: str, optional
Path to the output python file. If None, the output file name is the same as the input file name.
Default is None.
"""
python_file = ""

Expand Down Expand Up @@ -48,12 +50,10 @@ def convert_ipynb_to_gallery(input_file_name, output_file_name=None):

python_file = python_file.replace("\n%", "\n# %")
if output_file_name is None:
output_file_name = input_file_name
open(output_file_name.replace(".ipynb", ".py"), "w").write(python_file)
else:
if not output_file_name.endswith(".py"):
output_file_name = output_file_name + ".py"
open(output_file_name, "w").write(python_file)
output_file_name = input_file_name.replace(".ipynb", ".py")
if not output_file_name.endswith(".py"):
output_file_name = output_file_name + ".py"
open(output_file_name, "w").write(python_file)


if __name__ == "__main__":
Expand Down

0 comments on commit ec2f774

Please sign in to comment.