From b6d2eb19fd73fd13fee0954237a85e787fc26071 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 24 Sep 2022 13:07:09 +0200 Subject: [PATCH] MkDocs upgrade: migrate to class-based config schemas --- material/plugins/social/plugin.py | 28 ++++++++++++++-------------- material/plugins/tags/plugin.py | 15 ++++++++------- src/plugins/social/plugin.py | 28 ++++++++++++++-------------- src/plugins/tags/plugin.py | 15 ++++++++------- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/material/plugins/social/plugin.py b/material/plugins/social/plugin.py index 048ab988e..788f62fa5 100644 --- a/material/plugins/social/plugin.py +++ b/material/plugins/social/plugin.py @@ -28,7 +28,8 @@ from collections import defaultdict from hashlib import md5 from io import BytesIO from mkdocs.commands.build import DuplicateFilter -from mkdocs.config.config_options import Type +from mkdocs.config.base import Config +from mkdocs.config import config_options as opt from mkdocs.plugins import BasePlugin from shutil import copyfile from tempfile import TemporaryFile @@ -45,20 +46,19 @@ except ImportError: # Class # ----------------------------------------------------------------------------- +# Configuration scheme +class SocialPluginConfig(Config): + enabled = opt.Type(bool, default = True) + cache_dir = opt.Type(str, default = ".cache/plugin/social") + + # Options for social cards + cards = opt.Type(bool, default = True) + cards_dir = opt.Type(str, default = "assets/images/social") + cards_color = opt.Type(dict, default = {}) + cards_font = opt.Optional(opt.Type(str)) + # Social plugin -class SocialPlugin(BasePlugin): - - # Configuration scheme - config_scheme = ( - ("enabled", Type(bool, default = True)), - ("cache_dir", Type(str, default = ".cache/plugin/social")), - - # Options for social cards - ("cards", Type(bool, default = True)), - ("cards_dir", Type(str, default = "assets/images/social")), - ("cards_color", Type(dict, default = {})), - ("cards_font", Type(str, default = None)), - ) +class SocialPlugin(BasePlugin[SocialPluginConfig]): # Retrieve configuration def on_config(self, config): diff --git a/material/plugins/tags/plugin.py b/material/plugins/tags/plugin.py index b37db0bf1..14c925232 100644 --- a/material/plugins/tags/plugin.py +++ b/material/plugins/tags/plugin.py @@ -26,20 +26,21 @@ from collections import defaultdict from markdown.extensions.toc import slugify from mkdocs import utils from mkdocs.commands.build import DuplicateFilter -from mkdocs.config.config_options import Type +from mkdocs.config.base import Config +from mkdocs.config import config_options as opt from mkdocs.plugins import BasePlugin # ----------------------------------------------------------------------------- # Class # ----------------------------------------------------------------------------- -# Tags plugin -class TagsPlugin(BasePlugin): +# Configuration scheme +class TagsPluginConfig(Config): + tags_file = opt.Optional(opt.Type(str)) - # Configuration scheme - config_scheme = ( - ("tags_file", Type(str, required = False)), - ) + +# Tags plugin +class TagsPlugin(BasePlugin[TagsPluginConfig]): # Initialize plugin def on_config(self, config): diff --git a/src/plugins/social/plugin.py b/src/plugins/social/plugin.py index 048ab988e..788f62fa5 100644 --- a/src/plugins/social/plugin.py +++ b/src/plugins/social/plugin.py @@ -28,7 +28,8 @@ from collections import defaultdict from hashlib import md5 from io import BytesIO from mkdocs.commands.build import DuplicateFilter -from mkdocs.config.config_options import Type +from mkdocs.config.base import Config +from mkdocs.config import config_options as opt from mkdocs.plugins import BasePlugin from shutil import copyfile from tempfile import TemporaryFile @@ -45,20 +46,19 @@ except ImportError: # Class # ----------------------------------------------------------------------------- +# Configuration scheme +class SocialPluginConfig(Config): + enabled = opt.Type(bool, default = True) + cache_dir = opt.Type(str, default = ".cache/plugin/social") + + # Options for social cards + cards = opt.Type(bool, default = True) + cards_dir = opt.Type(str, default = "assets/images/social") + cards_color = opt.Type(dict, default = {}) + cards_font = opt.Optional(opt.Type(str)) + # Social plugin -class SocialPlugin(BasePlugin): - - # Configuration scheme - config_scheme = ( - ("enabled", Type(bool, default = True)), - ("cache_dir", Type(str, default = ".cache/plugin/social")), - - # Options for social cards - ("cards", Type(bool, default = True)), - ("cards_dir", Type(str, default = "assets/images/social")), - ("cards_color", Type(dict, default = {})), - ("cards_font", Type(str, default = None)), - ) +class SocialPlugin(BasePlugin[SocialPluginConfig]): # Retrieve configuration def on_config(self, config): diff --git a/src/plugins/tags/plugin.py b/src/plugins/tags/plugin.py index b37db0bf1..14c925232 100644 --- a/src/plugins/tags/plugin.py +++ b/src/plugins/tags/plugin.py @@ -26,20 +26,21 @@ from collections import defaultdict from markdown.extensions.toc import slugify from mkdocs import utils from mkdocs.commands.build import DuplicateFilter -from mkdocs.config.config_options import Type +from mkdocs.config.base import Config +from mkdocs.config import config_options as opt from mkdocs.plugins import BasePlugin # ----------------------------------------------------------------------------- # Class # ----------------------------------------------------------------------------- -# Tags plugin -class TagsPlugin(BasePlugin): +# Configuration scheme +class TagsPluginConfig(Config): + tags_file = opt.Optional(opt.Type(str)) - # Configuration scheme - config_scheme = ( - ("tags_file", Type(str, required = False)), - ) + +# Tags plugin +class TagsPlugin(BasePlugin[TagsPluginConfig]): # Initialize plugin def on_config(self, config):