myst_sphinx_gallery.utils#
Utility functions for the myst-sphinx-gallery package.
Functions
|
Convert a relative path to an absolute path. |
Return the path to the default thumbnail image. |
|
|
Ensure that the directory exists. |
|
Extract the title and tooltip from a file. |
|
Check if the file is in the folder. |
Return the path to the CSS file. |
|
|
Get the sub-gallery items from the given content. |
|
Get the title of a reStructuredText file. |
|
Load the markdown content from a Jupyter notebook file as string. |
Parse the files without the suffix. |
|
|
Print the run time of a function. |
|
Remove the number prefix from the example file/dir. |
|
Remove special characters from a string. |
|
Remove a directory if it exists. |
|
Remove a file if it exists. |
|
Convert a title to a reStructuredText section title. |
- myst_sphinx_gallery.utils.ensure_dir_exists(dir_path: Path) None[source]#
Ensure that the directory exists.
- dir_pathPath
The path to the directory.
- myst_sphinx_gallery.utils.safe_remove_dir(dir_path: Path) None[source]#
Remove a directory if it exists.
- myst_sphinx_gallery.utils.abs_path(path: Path | str, root_dir: Path | str, method: Literal['resolve', 'rglob'] = 'resolve') Path[source]#
Convert a relative path to an absolute path.
- Parameters:
path (Path | str) – The relative path.
root_dir (Path | str) – The root directory.
method (Literal["resolve", "rglob"], optional) –
The method to use for converting the path, by default “resolve”.
resolve: Use the
resolvemethod of the Path class to convert the path.rglob: try to find a matched path in the root directory using
rglob.
- Returns:
The absolute path.
- Return type:
Path
- myst_sphinx_gallery.utils.parse_files_without_suffix(path: Path | str) set[Path][source]#
Parse the files without the suffix.
Support wildcard in the path name to match multiple files.
- Parameters:
path (Path | str) – The path without the suffix.
- myst_sphinx_gallery.utils.get_rst_title(file_path: Path | str | None = None, content: str | None = None) str | None[source]#
Get the title of a reStructuredText file.
Either the file path or the content of the file should be provided.
- Parameters:
file_path (Path, optional) – The path to the reStructuredText file, by default None.
content (str, optional) – The content of the reStructuredText file, by default None. If not provided, the content is read from the file.
- myst_sphinx_gallery.utils.extract_title_and_tooltip(file_path: Path | str) tuple[str, str][source]#
Extract the title and tooltip from a file.
The file can be either a reStructuredText or a markdown/notebook file.
- myst_sphinx_gallery.utils.get_base_gallery_items(content: str, style: Literal['rst', 'md'] = 'rst') list[str][source]#
Get the sub-gallery items from the given content.
- myst_sphinx_gallery.utils.to_section_title(title: str) str[source]#
Convert a title to a reStructuredText section title.
- myst_sphinx_gallery.utils.remove_num_prefix(header_file: Path) tuple[str, str][source]#
Remove the number prefix from the example file/dir.
- myst_sphinx_gallery.utils.file_in_folder(file_path: Path | str, folder_path: Path | str) bool[source]#
Check if the file is in the folder.
Subdirectories are also considered.
- myst_sphinx_gallery.utils.print_run_time(func: callable) callable[source]#
Print the run time of a function.
- myst_sphinx_gallery.utils.load_nb_markdown(nb_file: Path) str[source]#
Load the markdown content from a Jupyter notebook file as string.