@@ -38,6 +38,15 @@ class OptionsData(NamedTuple):
3838PYLINT_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
4251def _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,10 @@ def _create_checker_section(
90107 continue
91108
92109 # Get current value of option
93- value = getattr (linter .config , option .name .replace ("-" , "_" ))
110+ try :
111+ value = DYNAMICALLY_DEFINED_OPTIONS [option .name ]["default" ]
112+ except KeyError :
113+ value = getattr (linter .config , option .name .replace ("-" , "_" ))
94114
95115 # Create a comment if the option has no value
96116 if value is None :
@@ -191,6 +211,5 @@ def setup(app: Sphinx) -> None:
191211
192212
193213if __name__ == "__main__" :
194- pass
195- # Uncomment to allow running this script by your local python interpreter
214+ print ("Uncomment the following line to allow running this script directly." )
196215 # build_options_page(None)
0 commit comments