teachbooks.external_content.process_toc module

Read and process table of contents files.

teachbooks.external_content.process_toc.chmod_git_files(foo, file, err)

Remove git files on Windows.

Solution from: https://stackoverflow.com/a/76356125

teachbooks.external_content.process_toc.external_to_local(mapping: dict[str, Any], external_path: str | Path, root: str | Path) dict[str, Any]

Modify mapping with the “external” key.

Retrieve external components locally, and fix ToC fields accordingly.

Parameters:
  • mapping – map to modify.

  • external_path – path where to store external components.

  • root – express paths to external components with respect to root.

Returns:

map with fields adjusted in order to refer to local resources.

teachbooks.external_content.process_toc.get_content_path(url: str) str

Get relative path of the external content from the URL path.

Parameters:

url – URL path to the external content

Returns:

repo path to the external content

teachbooks.external_content.process_toc.process_external_toc_entries(src: Path, dest: Path, book_root: Path, error_invalid_license: bool = True) Path

Parse external (git) ToC entries, checkout repos & write new ToC to file.

Parameters:
  • src – Path to the source table-of-contents yaml file.

  • dest – Path to the destination table-of-contents yaml file.

  • book_root – Path to the root of the book.

  • error_invalid_license – If true, and no valid license is found in an external repository, an error will be raised. Else only a warning.

Returns:

Path to the new table-of-contents yaml file, or the original file

if the toc was not modified.

teachbooks.external_content.process_toc.read_cloned_repos(log: Path) list[Path]

Read in cloned repo file to get paths to all cloned repos.

teachbooks.external_content.process_toc.write_toc_yaml(data: dict[str, str], path: str | Path, encoding: str = 'utf8', header: str | None = None) None

Write a ToC file.

Parameters:
  • data – site map

  • path – Target _toc.yml file path

  • encoding_toc.yml file character encoding

  • header – Commented out header to start toc file with.