MCPcopy Index your code
hub / github.com/bpython/bpython / __init__

Method __init__

bpython/config.py:210–376  ·  view source on GitHub ↗

Loads .ini configuration file and stores its values.

(self, config_path: Path | None = None)

Source from the content-addressed store, hash-verified

208 }
209
210 def __init__(self, config_path: Path | None = None) -> None:
211 """Loads .ini configuration file and stores its values."""
212
213 config = ConfigParser()
214 fill_config_with_default_values(config, self.defaults)
215 try:
216 if config_path is not None:
217 config.read(config_path)
218 except UnicodeDecodeError as e:
219 sys.stderr.write(
220 "Error: Unable to parse config file at '{}' due to an "
221 "encoding issue ({}). Please make sure to fix the encoding "
222 "of the file or remove it and then try again.\n".format(
223 config_path, e
224 )
225 )
226 sys.exit(1)
227
228 default_keys_to_commands = {
229 value: key for (key, value) in self.defaults["keyboard"].items()
230 }
231
232 def get_key_no_doublebind(command: str) -> str:
233 default_commands_to_keys = self.defaults["keyboard"]
234 requested_key = config.get("keyboard", command)
235
236 try:
237 default_command = default_keys_to_commands[requested_key]
238 if default_commands_to_keys[default_command] == config.get(
239 "keyboard", default_command
240 ):
241 setattr(self, f"{default_command}_key", "")
242 except KeyError:
243 pass
244
245 return requested_key
246
247 self.config_path = (
248 config_path.absolute() if config_path is not None else None
249 )
250 self.hist_file = Path(config.get("general", "hist_file")).expanduser()
251
252 self.dedent_after = config.getint("general", "dedent_after")
253 self.tab_length = config.getint("general", "tab_length")
254 self.auto_display_list = config.getboolean(
255 "general", "auto_display_list"
256 )
257 self.syntax = config.getboolean("general", "syntax")
258 self.arg_spec = config.getboolean("general", "arg_spec")
259 self.paste_time = config.getfloat("general", "paste_time")
260 self.single_undo_time = config.getfloat("general", "single_undo_time")
261 self.highlight_show_source = config.getboolean(
262 "general", "highlight_show_source"
263 )
264 self.editor = config.get("general", "editor")
265 self.hist_length = config.getint("general", "hist_length")
266 self.hist_duplicates = config.getboolean("general", "hist_duplicates")
267 self.flush_output = config.getboolean("general", "flush_output")

Callers

nothing calls this directly

Calls 8

get_config_homeFunction · 0.85
load_themeFunction · 0.85
supports_box_charsFunction · 0.85
from_stringMethod · 0.80
updateMethod · 0.80
writeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected