add script for live code

This commit is contained in:
Tom van Woudenberg 2025-03-20 11:23:21 +01:00
parent 2322687660
commit 8867006428
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,22 @@
import os
import json
def list_file_types(directory):
file_types = set()
for root, _, files in os.walk(directory):
for file in files:
_, ext = os.path.splitext(file)
if ext: # Only include files with extensions
file_types.add(ext)
return sorted(file_types)
def format_file_types(file_types):
formatted = [f"**/*{ext}" for ext in file_types]
return formatted
if __name__ == "__main__":
book_directory = r"c:\Users\tomvanwoudenbe\Git\book\book"
file_types = list_file_types(book_directory)
formatted_file_types = format_file_types(file_types)
print("File types in the directory (formatted):")
print(json.dumps(formatted_file_types))

View file

@ -85,7 +85,7 @@
"The `html_js_files` link calls for some required javascript files. `use_thebe_lite` makes sure you initiate our adapted sphinx thebe extensions. The `exclude_patterns` makes sure you import all files so that they can be accessed from your code, except for the files matching the patterns shown.\n",
"\n",
":::{note}\n",
"If you've a lot of big files which are not used by the code, the build book repository might grow a lot in size. Include unnecessary filetypes like images (i.e. `\"**/*.png`) to `exclude_patterns`. Make sure you use proper markdown or MyST syntax for referencing to images. Using HTML code might lead to figures not being available in the final book.\n",
"If you've a lot of big files which are not used by the code, the build book repository might grow a lot in size. Include unnecessary filetypes like images (i.e. `\"**/*.png`) to `exclude_patterns`. Make sure you use proper markdown or MyST syntax for referencing to images. Using HTML code might lead to figures not being available in the final book. You can use [this python script](./directories.py) to list all filetypes in your book.\n",
":::\n",
"\n",
"By `launch_buttons` you initiate the {fa}`rocket` --> {guilabel}`Live Code` on the top right corner of every page generated from a `.ipynb` file. \n",