From 88670064288f38fca39043cd6b85b49ccec49190 Mon Sep 17 00:00:00 2001 From: Tom van Woudenberg Date: Thu, 20 Mar 2025 11:23:21 +0100 Subject: [PATCH] add script for live code --- book/features/directories.py | 22 ++++++++++++++++++++++ book/features/live_code.ipynb | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 book/features/directories.py diff --git a/book/features/directories.py b/book/features/directories.py new file mode 100644 index 0000000..02bb2a8 --- /dev/null +++ b/book/features/directories.py @@ -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)) \ No newline at end of file diff --git a/book/features/live_code.ipynb b/book/features/live_code.ipynb index 3971cac..a4703a7 100644 --- a/book/features/live_code.ipynb +++ b/book/features/live_code.ipynb @@ -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",