Coverage for packages/workshop/src/livery/workshop/_examples.py: 100%

Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop, packages/extensions/ty, packages/extensions/ruff, packages/extensions/python, packages/extensions/pytest, packages/extensions/pyrefly, packages/extensions/nanobind, packages/extensions/mypy, packages/extensions/mkdocstrings, packages/extensions/lfs, packages/extensions/docs, packages/extensions/cpp, packages/extensions/coverage, packages/extensions/conan, packages/extensions/cmake, packages/extensions/claude, packages/extensions/clang-tidy, packages/extensions/clang-format, packages/extensions/changelog, packages/extensions/basedpyright ran.

1"""What a documentation example is: a python file under ``docs/examples/``.
2
3The examples plugin collects each example as one test, and the python
4extension's examples runner names examples to pytest; both ask
5[livery.workshop.is_example][]. This module imports no pytest, so the
6answer reads the same in a process that has none.
7"""
8
9from __future__ import annotations(empty)
10
11from typing import TYPE_CHECKING(empty)
12
13if TYPE_CHECKING:(empty)
14 from pathlib import Path
15
16
17def is_example(path: Path) -> bool:(empty)
18 """Tell whether *path* is a documentation example.
19
20 An example is a python file under a ``docs/examples/`` directory at
21 any depth of *path*, which the examples plugin collects as one
22 test. A ``conftest.py`` there is the package's setup around the
23 examples, never an example. Nothing is read from the disk.
24
25 Args:
26 path: The file, relative or absolute.
27
28 Returns:
29 True for an example; False for any other file.
30 """
31 if path.suffix != ".py" or path.name == "conftest.py":
32 return False
33 parts = path.parts
34 return any(parts[i : i + 2] == ("docs", "examples") for i in range(len(parts) - 1))