Skip to content

Commit

Permalink
tutorials: Use PythonExporter instead of ScriptExporter (#429)
Browse files Browse the repository at this point in the history
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: #429

Test Plan: CircleCI

Reviewed By: sdaulton

Differential Revision: D21249625

Pulled By: Balandat

fbshipit-source-id: d7901e29c8c9362c888bdf1dd0a8901c28c4f019
  • Loading branch information
Balandat authored and facebook-github-bot committed Apr 26, 2020
1 parent 5a2c72d commit 7b4405e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/parse_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
)
Expand Down

0 comments on commit 7b4405e

Please sign in to comment.