Skip to content

Commit 1e0040a

Browse files
committed
Only read "my" configuration files once, rather than once per call to read_my_cnf_files
1 parent 29059dd commit 1e0040a

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Upcoming (TBD)
2+
==============
3+
4+
Internal
5+
--------
6+
* Only read "my" configuration files once, rather than once per call to read_my_cnf_files
7+
8+
19
1.38.3 (2025/08/21)
210
==============
311

mycli/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from mycli.compat import WIN
4949
from mycli.completion_refresher import CompletionRefresher
5050
from mycli.config import get_mylogin_cnf_path, open_mylogin_cnf, read_config_files, str_to_bool, strip_matching_quotes, write_default_config
51+
from mycli.configobj import ConfigObj
5152
from mycli.key_bindings import mycli_bindings
5253
from mycli.lexer import MyCliLexer
5354
from mycli.packages import special
@@ -172,9 +173,6 @@ def __init__(
172173
self.logger = logging.getLogger(__name__)
173174
self.initialize_logging()
174175

175-
prompt_cnf = self.read_my_cnf_files(self.cnf_files, ["prompt"])["prompt"]
176-
self.prompt_format = prompt or prompt_cnf or c["main"]["prompt"] or self.default_prompt
177-
self.multiline_continuation_char = c["main"]["prompt_continuation"]
178176
keyword_casing = c["main"].get("keyword_casing", "auto")
179177

180178
self.query_history: list[Query] = []
@@ -200,6 +198,10 @@ def __init__(
200198
# There was an error reading the login path file.
201199
print("Error: Unable to read login path file.")
202200

201+
self.my_cnf = read_config_files(self.cnf_files, list_values=False)
202+
prompt_cnf = self.read_my_cnf(self.my_cnf, ["prompt"])["prompt"]
203+
self.prompt_format = prompt or prompt_cnf or c["main"]["prompt"] or self.default_prompt
204+
self.multiline_continuation_char = c["main"]["prompt_continuation"]
203205
self.prompt_app = None
204206

205207
def register_special_commands(self) -> None:
@@ -339,14 +341,13 @@ def initialize_logging(self) -> None:
339341
root_logger.debug("Initializing mycli logging.")
340342
root_logger.debug("Log file %r.", log_file)
341343

342-
def read_my_cnf_files(self, files: list[str | TextIOWrapper], keys: list[str]) -> dict[str, Any]:
344+
def read_my_cnf(self, cnf: ConfigObj, keys: list[str]) -> dict[str, Any]:
343345
"""
344-
Reads a list of config files and merges them. The last one will win.
345-
:param files: list of files to read
346+
Retrieves some keys from a configuration, applies transformations, returns a new configuration.
347+
:param cnf: configuration to read
346348
:param keys: list of keys to retrieve
347349
:returns: tuple, with None for missing keys.
348350
"""
349-
cnf = read_config_files(files, list_values=False)
350351

351352
sections = ["client", "mysqld"]
352353
key_transformations = {
@@ -433,7 +434,7 @@ def connect(
433434
"ssl-verify-server-cert": None,
434435
}
435436

436-
cnf = self.read_my_cnf_files(self.cnf_files, list(cnf.keys()))
437+
cnf = self.read_my_cnf(self.my_cnf, list(cnf.keys()))
437438

438439
# Fall back to config values only if user did not specify a value.
439440
database = database or cnf["database"]
@@ -1080,7 +1081,7 @@ def configure_pager(self) -> None:
10801081
if not os.environ.get("LESS"):
10811082
os.environ["LESS"] = "-RXF"
10821083

1083-
cnf = self.read_my_cnf_files(self.cnf_files, ["pager", "skip-pager"])
1084+
cnf = self.read_my_cnf(self.my_cnf, ["pager", "skip-pager"])
10841085
cnf_pager = cnf["pager"] or self.config["main"]["pager"]
10851086

10861087
# help Windows users who haven't edited the default myclirc

0 commit comments

Comments
 (0)