cdwilson · GitHub

@cdwilson

When an object's file lives in a virtual environment inside the
current working directory (for example a pydantic `BaseModel`
subclass documented with `preload_modules: [pydantic]` and an
in-project `.venv`), source blocks were labeled with the environment
path, like `.venv/lib/python3.10/site-packages/pydantic/main.py`.
The path is relative to the current working directory, so it slipped
past the `is_absolute()` check that normally keeps environment paths
out of rendered docs.
Add a `source_location` filter that strips everything up to and
including a `site-packages` directory from displayed source paths,
and use it for every source block label: merged `__init__`, class,
and function, in both themes. Centralizing the logic also fixes the
label for single-file modules installed directly in `site-packages`
(like `six.py`), whose package-relative path still contained the
environment directory. Labels of objects belonging to the documented
package itself are unchanged.
Issue mkdocstrings#333: mkdocstrings#333
Assisted-by: Claude:claude-fable-5

Read the original on github.com ↗