haystack/docs/_src/tutorials/tutorials/convert_ipynb.py
Sara Zan a59bca3661
Apply black formatting (#2115)
* Testing black on ui/

* Applying black on docstores

* Add latest docstring and tutorial changes

* Create a single GH action for Black and docs to reduce commit noise to the minimum, slightly refactor the OpenAPI action too

* Remove comments

* Relax constraints on pydoc-markdown

* Split temporary black from the docs. Pydoc-markdown was obsolete and needs a separate PR to upgrade

* Fix a couple of bugs

* Add a type: ignore that was missing somehow

* Give path to black

* Apply Black

* Apply Black

* Relocate a couple of type: ignore

* Update documentation

* Make Linux CI run after applying Black

* Triggering Black

* Apply Black

* Remove dependency, does not work well

* Remove manually double trailing commas

* Update documentation

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-02-03 13:43:18 +01:00

32 lines
786 B
Python

import re
from nbconvert import MarkdownExporter
import os
from pathlib import Path
from headers import headers
def atoi(text):
return int(text) if text.isdigit() else text
def natural_keys(text):
test = [atoi(c) for c in re.split("(\d+)", text)]
return test
dir = Path("../../../../tutorials")
notebooks = [x for x in os.listdir(dir) if x[-6:] == ".ipynb"]
# sort notebooks based on numbers within name of notebook
notebooks = sorted(notebooks, key=lambda x: natural_keys(x))
e = MarkdownExporter(exclude_output=True)
for i, nb in enumerate(notebooks):
body, resources = e.from_filename(dir / nb)
print(f"Processing {dir}/{nb}")
with open(str(i + 1) + ".md", "w", encoding="utf-8") as f:
f.write(headers[i + 1] + "\n\n")
f.write(body)