From 7b4405e5b80742fd323155f8e8c3719e18829892 Mon Sep 17 00:00:00 2001 From: Max Balandat Date: Sun, 26 Apr 2020 10:34:09 -0700 Subject: [PATCH] tutorials: Use PythonExporter instead of ScriptExporter (#429) Summary: We want to export python, so this is what we should do. Also, this replaces the default `#!/usr/bin/env python` shebang in the generated .py files with `#!/usr/bin/env python3`. Pull Request resolved: https://github.com/pytorch/botorch/pull/429 Test Plan: CircleCI Reviewed By: sdaulton Differential Revision: D21249625 Pulled By: Balandat fbshipit-source-id: d7901e29c8c9362c888bdf1dd0a8901c28c4f019 --- scripts/parse_tutorials.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/parse_tutorials.py b/scripts/parse_tutorials.py index b48f9db0bf..59acc9cc19 100644 --- a/scripts/parse_tutorials.py +++ b/scripts/parse_tutorials.py @@ -12,7 +12,7 @@ import nbformat from bs4 import BeautifulSoup -from nbconvert import HTMLExporter, ScriptExporter +from nbconvert import HTMLExporter, PythonExporter TEMPLATE = """const CWD = process.cwd(); @@ -92,8 +92,10 @@ def gen_tutorials(repo_dir: str) -> None: ) with open(ipynb_out_path, "w") as ipynb_outfile: ipynb_outfile.write(nb_str) - exporter = ScriptExporter() + exporter = PythonExporter() script, meta = exporter.from_notebook_node(nb) + # make sure to use python3 shebang + script = script.replace("#!/usr/bin/env python", "#!/usr/bin/env python3") py_out_path = os.path.join( repo_dir, "website", "static", "files", "{}.py".format(tid) )