Skip to content

Commit b2892d8

Browse files
[doc] Add the possibility to set dynamic values in doc
1 parent 4d55077 commit b2892d8

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

doc/exts/pylint_options.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ class OptionsData(NamedTuple):
3838
PYLINT_USERGUIDE_PATH = PYLINT_BASE_PATH / "doc" / "user_guide"
3939
"""Path to the messages documentation folder."""
4040

41+
DYNAMICALLY_DEFINED_OPTIONS: dict[str, dict[str, str]] = {
42+
# Option name, key / values we want to modify
43+
"py-version": {"default": "sys.version_info[:2]"},
44+
"spelling-dict": {
45+
"choices": "Values from 'enchant.Broker().list_dicts()' depending on your local enchant installation",
46+
"help": "Spelling dictionary name. Available dictionaries depends on your local enchant installation",
47+
},
48+
}
49+
4150

4251
def _register_all_checkers_and_extensions(linter: PyLinter) -> None:
4352
"""Registers all checkers and extensions found in the default folders."""
@@ -49,12 +58,20 @@ def _get_all_options(linter: PyLinter) -> OptionsDataDict:
4958
"""Get all options registered to a linter and return the data."""
5059
all_options: OptionsDataDict = defaultdict(list)
5160
for checker in sorted(linter.get_checkers()):
52-
ch_name = checker.name
53-
for option in checker.options:
54-
all_options[ch_name].append(
61+
checker_name = checker.name
62+
for option_name, option_info in checker.options:
63+
changes_to_do = DYNAMICALLY_DEFINED_OPTIONS.get(option_name, {})
64+
if changes_to_do:
65+
for key_to_change, new_value in changes_to_do.items():
66+
print(
67+
f"Doc value for {option_name!r}['{key_to_change}'] changed to "
68+
f"{new_value!r} (instead of {option_info[key_to_change]!r})"
69+
)
70+
option_info[key_to_change] = new_value
71+
all_options[checker_name].append(
5572
OptionsData(
56-
option[0],
57-
option[1],
73+
option_name,
74+
option_info,
5875
checker,
5976
getmodule(checker).__name__.startswith("pylint.extensions."), # type: ignore[union-attr]
6077
)
@@ -90,7 +107,13 @@ def _create_checker_section(
90107
continue
91108

92109
# Get current value of option
93-
value = getattr(linter.config, option.name.replace("-", "_"))
110+
if (
111+
option.name not in DYNAMICALLY_DEFINED_OPTIONS
112+
or "default" not in DYNAMICALLY_DEFINED_OPTIONS[option.name]
113+
):
114+
value = getattr(linter.config, option.name.replace("-", "_"))
115+
else:
116+
value = DYNAMICALLY_DEFINED_OPTIONS[option.name]["default"]
94117

95118
# Create a comment if the option has no value
96119
if value is None:
@@ -191,6 +214,5 @@ def setup(app: Sphinx) -> None:
191214

192215

193216
if __name__ == "__main__":
194-
pass
195-
# Uncomment to allow running this script by your local python interpreter
217+
print("Uncomment the line following this print to make this script do something!")
196218
# build_options_page(None)

doc/user_guide/configuration/all-options.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Standard Checkers
171171
""""""""""""
172172
*Minimum Python version to use for version dependent checks. Will default to the version used to run pylint.*
173173

174-
**Default:** ``(3, 11)``
174+
**Default:** ``sys.version_info[:2]``
175175

176176

177177
--recursive
@@ -271,7 +271,7 @@ Standard Checkers
271271
272272
persistent = true
273273
274-
py-version = [3, 11]
274+
py-version = "sys.version_info[:2]"
275275
276276
recursive = false
277277
@@ -1298,7 +1298,7 @@ Standard Checkers
12981298

12991299
--spelling-dict
13001300
"""""""""""""""
1301-
*Spelling dictionary name. No available dictionaries : You need to install both the python package and the system dependency for enchant to work..*
1301+
*Spelling dictionary name. Available dictionaries depends on your local enchant installation*
13021302

13031303
**Default:** ``""``
13041304

@@ -1344,7 +1344,7 @@ Standard Checkers
13441344
[tool.pylint.spelling]
13451345
max-spelling-suggestions = 4
13461346
1347-
# Possible choices: ['', 'en', 'en_AU', 'en_CA', 'en_GB', 'en_US']
1347+
# Possible choices: Values from 'enchant.Broker().list_dicts()' depending on your local enchant installation
13481348
spelling-dict = ""
13491349
13501350
spelling-ignore-comment-directives = "fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:"

0 commit comments

Comments
 (0)