-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathutils.py
44 lines (29 loc) · 1.11 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Utility functions and classes that aren't limited to any scenario."""
import logging
from typing import Dict, Optional, TypeVar
from mkdocs.config.defaults import MkDocsConfig
from mkdocs.plugins import BasePlugin
Plugin = TypeVar("Plugin", bound=BasePlugin)
"""Plugin Instance Type"""
def get_plugin(name: str, config: MkDocsConfig) -> Optional[Plugin]:
"""Returns a plugin instance"""
plugins: Dict[str, BasePlugin] = config["plugins"]
instance: Plugin = plugins.get(name)
if instance:
return instance
scoped_name: str = f"/{name}"
# If the plugin was not found using the name
# then look for a theme-namespaced plugin.
for n, p in plugins.items():
if n.endswith(scoped_name):
return p
return None
class I18nLoggingFilter:
"""Avoid logging duplicate build time messages."""
def __init__(self, *_, **__):
self.filtered_prefixes = set()
def __call__(self, record: logging.LogRecord) -> bool:
for prefix in self.filtered_prefixes:
if record.msg.startswith(prefix):
return False
return True