Skip to content

Commit 974c495

Browse files
committed
Added plugin config definition
1 parent 93e7ff0 commit 974c495

File tree

4 files changed

+51
-50
lines changed

4 files changed

+51
-50
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ We only use `material-mkdocs` as base styles because Backstage also uses the `Ma
157157

158158
## Changelog
159159

160+
### 1.5.4
161+
162+
- Added proper plugin config to fix `Unrecognised configuration name` error when any config is provided
163+
160164
### 1.5.3
161165

162166
- Added support for PyMdown Blocks extensions

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
setup(
3030
name="mkdocs-techdocs-core",
31-
version="1.5.3",
31+
version="1.5.4",
3232
description="The core MkDocs plugin used by Backstage's TechDocs as a wrapper around "
3333
"multiple MkDocs plugins and Python Markdown extensions",
3434
long_description=long_description,

techdocs_core/core.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import tempfile
1818
import logging
1919
import os
20+
21+
from mkdocs.config import Config, config_options
2022
from mkdocs.plugins import BasePlugin
2123
from mkdocs.theme import Theme
2224
from mkdocs.contrib.search import SearchPlugin
@@ -30,7 +32,12 @@
3032
TECHDOCS_DEFAULT_THEME = "material"
3133

3234

33-
class TechDocsCore(BasePlugin):
35+
class TechDocsCoreConfig(Config):
36+
use_material_search = config_options.Type(bool, default=False)
37+
use_pymdownx_blocks = config_options.Type(bool, default=False)
38+
39+
40+
class TechDocsCore(BasePlugin[TechDocsCoreConfig]):
3441
def __init__(self):
3542
# This directory will be removed automatically once the docs are built
3643
# MkDocs needs a directory for the theme with the `techdocs_metadata.json` file
@@ -76,12 +83,8 @@ def on_config(self, config):
7683
config["theme"].dirs.append(self.tmp_dir_techdocs_theme.name)
7784

7885
# Plugins
79-
use_material_search = config["plugins"]["techdocs-core"].config.get(
80-
"use_material_search", False
81-
)
82-
use_pymdownx_blocks = config["plugins"]["techdocs-core"].config.get(
83-
"use_pymdownx_blocks", False
84-
)
86+
use_material_search = self.config["use_material_search"]
87+
use_pymdownx_blocks = self.config["use_pymdownx_blocks"]
8588
del config["plugins"]["techdocs-core"]
8689

8790
if use_material_search:

techdocs_core/test_core.py

+36-42
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,77 @@ class DummyTechDocsCorePlugin(plugins.BasePlugin):
1616
pass
1717

1818

19-
class TestTechDocsCoreConfig(unittest.TestCase):
19+
class TestTechDocsCore(unittest.TestCase):
2020
def setUp(self):
21-
self.techdocscore = TechDocsCore()
2221
self.plugin_collection = plugins.PluginCollection()
2322
plugin = DummyTechDocsCorePlugin()
2423
self.plugin_collection["techdocs-core"] = plugin
25-
self.mkdocs_yaml_config = {"plugins": self.plugin_collection}
26-
# Note: in reality, config["theme"] is always an instance of Theme
27-
self.mkdocs_yaml_config["theme"] = get_default_theme()
24+
self.techdocscore = TechDocsCore()
25+
self.techdocscore.load_config(
26+
{"plugins": self.plugin_collection, "theme": get_default_theme()}
27+
)
2828

2929
def test_removes_techdocs_core_plugin_from_config(self):
30-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
30+
final_config = self.techdocscore.on_config(self.techdocscore.config)
3131
self.assertTrue("techdocs-core" not in final_config["plugins"])
3232

3333
def test_merge_default_config_and_user_config(self):
34-
self.mkdocs_yaml_config["markdown_extension"] = []
35-
self.mkdocs_yaml_config["mdx_configs"] = {}
36-
self.mkdocs_yaml_config["markdown_extension"].append(["toc"])
37-
self.mkdocs_yaml_config["mdx_configs"]["toc"] = {"toc_depth": 3}
38-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
34+
self.techdocscore.config["markdown_extension"] = []
35+
self.techdocscore.config["mdx_configs"] = {}
36+
self.techdocscore.config["markdown_extension"].append(["toc"])
37+
self.techdocscore.config["mdx_configs"]["toc"] = {"toc_depth": 3}
38+
final_config = self.techdocscore.on_config(self.techdocscore.config)
3939
self.assertTrue("toc" in final_config["mdx_configs"])
4040
self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
4141
self.assertTrue("toc_depth" in final_config["mdx_configs"]["toc"])
4242
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
4343

4444
def test_override_default_config_with_user_config(self):
45-
self.mkdocs_yaml_config["markdown_extension"] = []
46-
self.mkdocs_yaml_config["mdx_configs"] = {}
47-
self.mkdocs_yaml_config["markdown_extension"].append(["toc"])
48-
self.mkdocs_yaml_config["mdx_configs"]["toc"] = {"permalink": False}
49-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
45+
self.techdocscore.config["markdown_extension"] = []
46+
self.techdocscore.config["mdx_configs"] = {}
47+
self.techdocscore.config["markdown_extension"].append(["toc"])
48+
self.techdocscore.config["mdx_configs"]["toc"] = {"permalink": False}
49+
final_config = self.techdocscore.on_config(self.techdocscore.config)
5050
self.assertTrue("toc" in final_config["mdx_configs"])
5151
self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
5252
self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
5353
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
5454

5555
def test_theme_overrides_removed_when_name_is_not_material(self):
5656
# we want to force the theme mkdocs to this test
57-
self.mkdocs_yaml_config["theme"] = Theme(name="mkdocs")
58-
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
59-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
57+
self.techdocscore.config["theme"] = Theme(name="mkdocs")
58+
self.techdocscore.config["theme"]["features"] = ["navigation.sections"]
59+
final_config = self.techdocscore.on_config(self.techdocscore.config)
6060
self.assertFalse("navigation.sections" in final_config["theme"]["features"])
6161

6262
def test_theme_overrides_when_name_is_material(self):
63-
self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
64-
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
65-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
63+
self.techdocscore.config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
64+
self.techdocscore.config["theme"]["features"] = ["navigation.sections"]
65+
final_config = self.techdocscore.on_config(self.techdocscore.config)
6666
self.assertTrue("navigation.sections" in final_config["theme"]["features"])
6767

6868
def test_theme_overrides_techdocs_metadata(self):
69-
self.mkdocs_yaml_config["theme"] = Theme(
69+
self.techdocscore.config["theme"] = Theme(
7070
name=TECHDOCS_DEFAULT_THEME, static_templates=["my_static_temples"]
7171
)
72-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
72+
final_config = self.techdocscore.on_config(self.techdocscore.config)
7373
self.assertTrue("my_static_temples" in final_config["theme"].static_templates)
7474
self.assertTrue(
7575
"techdocs_metadata.json" in final_config["theme"].static_templates
7676
)
7777

7878
def test_theme_overrides_dirs(self):
7979
custom_theme_dir = "/tmp/my_custom_theme_dir"
80-
self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
81-
self.mkdocs_yaml_config["theme"].dirs.append(custom_theme_dir)
82-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
80+
self.techdocscore.config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
81+
self.techdocscore.config["theme"].dirs.append(custom_theme_dir)
82+
final_config = self.techdocscore.on_config(self.techdocscore.config)
8383
self.assertTrue(custom_theme_dir in final_config["theme"].dirs)
8484
self.assertTrue(
8585
self.techdocscore.tmp_dir_techdocs_theme.name in final_config["theme"].dirs
8686
)
8787

8888
def test_template_renders__multiline_value_as_valid_json(self):
89-
self.techdocscore.on_config(self.mkdocs_yaml_config)
89+
self.techdocscore.on_config(self.techdocscore.config)
9090
env = Environment(
9191
loader=PackageLoader(
9292
"techdocs_core", self.techdocscore.tmp_dir_techdocs_theme.name
@@ -103,40 +103,35 @@ def test_template_renders__multiline_value_as_valid_json(self):
103103
self.assertEqual(config, as_json)
104104

105105
def test_restrict_snippet_base_path(self):
106-
self.mkdocs_yaml_config["mdx_configs"] = {
106+
self.techdocscore.config["mdx_configs"] = {
107107
"pymdownx.snippets": {"restrict_base_path": False}
108108
}
109109

110-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
110+
final_config = self.techdocscore.on_config(self.techdocscore.config)
111111

112112
self.assertEqual(
113113
final_config["mdx_configs"]["pymdownx.snippets"]["restrict_base_path"],
114114
True,
115115
)
116116

117117
def test_material_search(self):
118-
self.plugin_collection["techdocs-core"].load_config(
119-
{"use_material_search": True}
120-
)
121-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
118+
self.techdocscore.config["use_material_search"] = True
119+
final_config = self.techdocscore.on_config(self.techdocscore.config)
122120

123121
self.assertEqual(
124122
final_config["plugins"]["search"].__module__,
125123
"material.plugins.search.plugin",
126124
)
127125

128126
def test_default_search(self):
129-
self.plugin_collection["techdocs-core"].load_config({})
130-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
127+
final_config = self.techdocscore.on_config(self.techdocscore.config)
131128
self.assertEqual(
132129
final_config["plugins"]["search"].__module__, "mkdocs.contrib.search"
133130
)
134131

135132
def test_pymdownx_blocks(self):
136-
self.plugin_collection["techdocs-core"].load_config(
137-
{"use_pymdownx_blocks": True}
138-
)
139-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
133+
self.techdocscore.config["use_pymdownx_blocks"] = True
134+
final_config = self.techdocscore.on_config(self.techdocscore.config)
140135

141136
self.assertTrue(
142137
"pymdownx.blocks.admonition" in final_config["markdown_extensions"]
@@ -160,8 +155,7 @@ def test_pymdownx_blocks(self):
160155
self.assertFalse("pymdownx.tabbed" in final_config["mdx_configs"])
161156

162157
def test_default_pymdownx(self):
163-
self.plugin_collection["techdocs-core"].load_config({})
164-
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
158+
final_config = self.techdocscore.on_config(self.techdocscore.config)
165159

166160
self.assertFalse(
167161
"pymdownx.blocks.admonition" in final_config["markdown_extensions"]

0 commit comments

Comments
 (0)