Coverage for structured_tutorials / runners / local.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-04 13:17 +0200
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-04 13:17 +0200
1# Copyright (c) 2025 Mathias Ertl
2# Licensed under the MIT License. See LICENSE file for details.
4"""Runner that runs a tutorial on the local machine."""
6import logging
7import os
8import shutil
9from pathlib import Path
10from typing import Any
12from structured_tutorials.runners.base import RunnerBase
14log = logging.getLogger(__name__)
17class LocalTutorialRunner(RunnerBase):
18 """Runner implementation that runs a tutorial on the local machine."""
20 def chdir(self, path: str, options: dict[str, Any]) -> None:
21 os.chdir(str(path))
23 def copy_file(self, source: Path, destination: Path, options: dict[str, Any]) -> None:
24 destination.parent.mkdir(parents=True, exist_ok=True)
25 shutil.copy(source, destination)
27 def write_file_from_string(self, contents: str, destination: Path, options: dict[str, Any]) -> None:
28 """Write a file from a string."""
29 destination.parent.mkdir(parents=True, exist_ok=True)
30 with open(destination, "w") as destination_stream:
31 destination_stream.write(contents)