|
4 | 4 |
|
5 | 5 | from xrlint.plugin import Plugin |
6 | 6 | from xrlint.rule import RuleConfig |
| 7 | +from xrlint.config import plugins_from_entry_points |
7 | 8 |
|
8 | 9 | # for icons, see |
9 | 10 | # https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/ |
|
25 | 26 |
|
26 | 27 |
|
27 | 28 | def write_rule_ref_page(): |
28 | | - import xrlint.plugins.core |
29 | | - import xrlint.plugins.xcube |
30 | | - import xrlint.plugins.acdd |
31 | | - |
32 | | - core = xrlint.plugins.core.export_plugin() |
33 | | - xcube = xrlint.plugins.xcube.export_plugin() |
34 | | - acdd = xrlint.plugins.acdd.export_plugin() |
35 | | - with open("docs/rule-ref.md", "w") as stream: |
| 29 | + import mkdocs_gen_files |
| 30 | + |
| 31 | + plugins = plugins_from_entry_points() |
| 32 | + |
| 33 | + print(f"Generating rule reference for discovered plugins: {list(plugins.keys())}") |
| 34 | + |
| 35 | + with mkdocs_gen_files.open("rule-ref.md", "w") as stream: |
36 | 36 | stream.write("# Rule Reference\n\n") |
37 | 37 | stream.write( |
38 | 38 | "This page is auto-generated from XRLint's builtin" |
39 | | - " rules (`python -m mkruleref`).\n" |
| 39 | + " rules.\n" |
40 | 40 | "New rules will be added by upcoming XRLint releases.\n\n" |
41 | 41 | ) |
42 | | - stream.write("## Core Rules\n\n") |
43 | | - write_plugin_rules(stream, core) |
44 | | - stream.write("## xcube Rules\n\n") |
45 | | - write_plugin_rules(stream, xcube) |
46 | | - stream.write("## ACDD Rules\n\n") |
47 | | - write_plugin_rules(stream, acdd) |
| 42 | + for plugin_name in sorted(plugins.keys()): |
| 43 | + plugin = plugins[plugin_name] |
| 44 | + stream.write(f"## {plugin.meta.name} Rules\n\n") |
| 45 | + if plugin.meta.ref: |
| 46 | + stream.write(f"- `{plugin.meta.ref.removesuffix(':export_plugin')}`\n") |
| 47 | + if plugin.meta.docs_url: |
| 48 | + stream.write(f"- [Documentation]({plugin.meta.docs_url})\n\n") |
| 49 | + write_plugin_rules(stream, plugin) |
48 | 50 |
|
49 | 51 |
|
50 | 52 | def write_plugin_rules(stream, plugin: Plugin): |
@@ -86,5 +88,4 @@ def get_plugin_rule_configs(plugin: Plugin) -> dict[str, dict[str, RuleConfig]]: |
86 | 88 | return config_rules |
87 | 89 |
|
88 | 90 |
|
89 | | -if __name__ == "__main__": |
90 | | - write_rule_ref_page() |
| 91 | +write_rule_ref_page() |
0 commit comments