Skip to content

Commit c4dda40

Browse files
[doc] Add the possibility to set dynamic values in doc
1 parent 267ee57 commit c4dda40

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

doc/exts/pylint_options.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ 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+
# At least default need to be defined
44+
"py-version": {"default": "sys.version_info[:2]"},
45+
"spelling-dict": {
46+
"choices": "enchant.Broker().list_dicts()",
47+
"default": "",
48+
"help": "Spelling dictionary name. Available dictionaries depends on your local enchant installation",
49+
},
50+
}
51+
4152

4253
def _register_all_checkers_and_extensions(linter: PyLinter) -> None:
4354
"""Registers all checkers and extensions found in the default folders."""
@@ -49,12 +60,20 @@ def _get_all_options(linter: PyLinter) -> OptionsDataDict:
4960
"""Get all options registered to a linter and return the data."""
5061
all_options: OptionsDataDict = defaultdict(list)
5162
for checker in sorted(linter.get_checkers()):
52-
ch_name = checker.name
53-
for option in checker.options:
54-
all_options[ch_name].append(
63+
checker_name = checker.name
64+
for option_name, option_info in checker.options:
65+
changes_to_do = DYNAMICALLY_DEFINED_OPTIONS.get(option_name, {})
66+
if changes_to_do:
67+
for key_to_change, new_value in changes_to_do.items():
68+
print(
69+
f"Doc value for {option_name!r}['{key_to_change}'] changed to "
70+
f"{new_value!r} (instead of {option_info[key_to_change]!r})"
71+
)
72+
option_info[key_to_change] = new_value
73+
all_options[checker_name].append(
5574
OptionsData(
56-
option[0],
57-
option[1],
75+
option_name,
76+
option_info,
5877
checker,
5978
getmodule(checker).__name__.startswith("pylint.extensions."), # type: ignore[union-attr]
6079
)
@@ -90,7 +109,10 @@ def _create_checker_section(
90109
continue
91110

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

95117
# Create a comment if the option has no value
96118
if value is None:

doc/user_guide/configuration/all-options.rst

Lines changed: 3 additions & 3 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
@@ -1285,7 +1285,7 @@ Standard Checkers
12851285

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

12901290
**Default:** ``""``
12911291

0 commit comments

Comments
 (0)