1"""What a documentation example is: a python file under ``docs/examples/``.
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"""
14 from pathlib import Path
18 """Tell whether *path* is a documentation example.
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.
25 Args:
26 path: The file, relative or absolute.
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))