Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix: Detecting paths relative to template directory in logging
- Loading branch information
Showing
with
11 additions
and
4 deletions.
-
+2
−1
src/mkdocstrings/handlers/base.py
-
+9
−3
src/mkdocstrings/loggers.py
|
|
@@ -23,6 +23,7 @@ |
|
|
from mkdocstrings.loggers import get_template_logger |
|
|
|
|
|
handlers_cache: Dict[str, Any] = {} |
|
|
TEMPLATES_DIR = Path(__file__).parent.parent / "templates" |
|
|
|
|
|
|
|
|
class CollectionError(Exception): |
|
|
@@ -120,7 +121,7 @@ def __init__(self, directory: str, theme: str, custom_templates: Optional[str] = |
|
|
if custom_templates is not None: |
|
|
paths.append(Path(custom_templates) / directory / theme) |
|
|
|
|
|
themes_dir = Path(__file__).parent.parent / "templates" / directory |
|
|
themes_dir = TEMPLATES_DIR / directory |
|
|
|
|
|
paths.append(themes_dir / theme) |
|
|
|
|
|
|
|
|
@@ -1,12 +1,15 @@ |
|
|
"""Logging functions.""" |
|
|
|
|
|
import logging |
|
|
from pathlib import Path |
|
|
from typing import Callable, Optional |
|
|
|
|
|
from jinja2 import contextfunction |
|
|
from jinja2.runtime import Context |
|
|
from mkdocs.utils import warning_filter |
|
|
|
|
|
from mkdocstrings.handlers import base |
|
|
|
|
|
|
|
|
class LoggerAdapter(logging.LoggerAdapter): |
|
|
"""A logger adapter to prefix messages.""" |
|
|
@@ -102,9 +105,12 @@ def get_template_path(context: Context) -> str: |
|
|
Returns: |
|
|
The relative path to the template. |
|
|
""" |
|
|
template = context.environment.get_template(context.name) |
|
|
if template.filename: |
|
|
return template.filename.rsplit("/templates/", 1)[1] |
|
|
filename = context.environment.get_template(context.name).filename |
|
|
if filename: |
|
|
try: |
|
|
return str(Path(filename).relative_to(base.TEMPLATES_DIR)) |
|
|
except ValueError: |
|
|
return filename |
|
|
return context.name |
|
|
|
|
|
|
|
|
|