66import threading
77from typing import IO , Literal
88
9+ from cli_helpers .tabular_output import TabularOutputFormatter
910from prompt_toolkit .formatted_text import to_formatted_text
1011from prompt_toolkit .shortcuts import PromptSession
1112import sqlparse
2122from mycli .client_commands import ClientCommandsMixin
2223from mycli .client_connection import ClientConnectionMixin
2324from mycli .client_query import ClientQueryMixin
25+ from mycli .clistyle import style_factory_helpers , style_factory_ptoolkit
26+ from mycli .completion_refresher import CompletionRefresher
27+ from mycli .config import get_mylogin_cnf_path , open_mylogin_cnf , read_config_files , write_default_config
2428from mycli .constants import DEFAULT_PROMPT
2529from mycli .main_modes import repl as repl_package
2630from mycli .output import OutputMixin
2731from mycli .packages import special
2832from mycli .packages .special .favoritequeries import FavoriteQueries
2933from mycli .packages .tabular_output import sql_format
34+ from mycli .schema_prefetcher import SchemaPrefetcher
35+ from mycli .sqlcompleter import SQLCompleter
3036from mycli .sqlexecute import SQLExecute
3137from mycli .types import Query
3238
@@ -94,16 +100,15 @@ def __init__(
94100
95101 # Load config.
96102 config_files : list [str | IO [str ]] = self .system_config_files + [myclirc ] + [self .pwd_config_file ]
97- from mycli import main as main_module
98103
99- c = self .config = main_module . read_config_files (config_files )
104+ c = self .config = read_config_files (config_files )
100105 # this parallel config exists to
101106 # * compare with my.cnf
102107 # * support the --checkup feature
103108 # todo: after removing my.cnf, create the parallel configs only when --checkup is set
104- self .config_without_package_defaults = main_module . read_config_files (config_files , ignore_package_defaults = True )
109+ self .config_without_package_defaults = read_config_files (config_files , ignore_package_defaults = True )
105110 # this parallel config exists to compare with my.cnf support the --checkup feature
106- self .config_without_user_options = main_module . read_config_files (config_files , ignore_user_options = True )
111+ self .config_without_user_options = read_config_files (config_files , ignore_user_options = True )
107112 self .multi_line = c ["main" ].as_bool ("multi_line" )
108113 self .key_bindings = c ["main" ]["key_bindings" ]
109114 self .emacs_ttimeoutlen = c ['keys' ].as_float ('emacs_ttimeoutlen' )
@@ -120,8 +125,8 @@ def __init__(
120125 FavoriteQueries .instance = FavoriteQueries .from_config (self .config )
121126
122127 self .dsn_alias : str | None = None
123- self .main_formatter = main_module . TabularOutputFormatter (format_name = c ["main" ]["table_format" ])
124- self .redirect_formatter = main_module . TabularOutputFormatter (format_name = c ["main" ].get ("redirect_format" , "csv" ))
128+ self .main_formatter = TabularOutputFormatter (format_name = c ["main" ]["table_format" ])
129+ self .redirect_formatter = TabularOutputFormatter (format_name = c ["main" ].get ("redirect_format" , "csv" ))
125130 sql_format .register_new_formatter (self .main_formatter )
126131 sql_format .register_new_formatter (self .redirect_formatter )
127132 self .main_formatter .mycli = self
@@ -131,9 +136,9 @@ def __init__(
131136 if cli_verbosity :
132137 self .verbosity = cli_verbosity
133138 self .cli_style = c ["colors" ]
134- self .ptoolkit_style = main_module . style_factory_ptoolkit (self .syntax_style , self .cli_style )
135- self .helpers_style = main_module . style_factory_helpers (self .syntax_style , self .cli_style )
136- self .helpers_warnings_style = main_module . style_factory_helpers (self .syntax_style , self .cli_style , warnings = True )
139+ self .ptoolkit_style = style_factory_ptoolkit (self .syntax_style , self .cli_style )
140+ self .helpers_style = style_factory_helpers (self .syntax_style , self .cli_style )
141+ self .helpers_warnings_style = style_factory_helpers (self .syntax_style , self .cli_style , warnings = True )
137142 self .wider_completion_menu = c ["main" ].as_bool ("wider_completion_menu" )
138143 c_dest_warning = c ["main" ].as_bool ("destructive_warning" )
139144 self .destructive_warning = c_dest_warning if warn is None else warn
@@ -153,7 +158,7 @@ def __init__(
153158
154159 # Write user config if system config wasn't the last config loaded.
155160 if c .filename not in self .system_config_files and not os .path .exists (myclirc ):
156- main_module . write_default_config (myclirc )
161+ write_default_config (myclirc )
157162
158163 # audit log
159164 if self .logfile is None and "audit_log" in c ["main" ]:
@@ -163,11 +168,11 @@ def __init__(
163168 self .echo ("Error: Unable to open the audit log file. Your queries will not be logged." , err = True , fg = "red" )
164169 self .logfile = False
165170
166- self .completion_refresher = main_module . CompletionRefresher ()
171+ self .completion_refresher = CompletionRefresher ()
167172 self .prefetch_schemas_mode = c ["main" ].get ("prefetch_schemas_mode" , "always" ) or "always"
168173 raw_prefetch_list = c ["main" ].as_list ("prefetch_schemas_list" ) if "prefetch_schemas_list" in c ["main" ] else []
169174 self .prefetch_schemas_list = [s .strip () for s in raw_prefetch_list if s and s .strip ()]
170- self .schema_prefetcher = main_module . SchemaPrefetcher (self )
175+ self .schema_prefetcher = SchemaPrefetcher (self )
171176
172177 self .logger = logging .getLogger (__name__ )
173178 self .initialize_logging ()
@@ -180,7 +185,7 @@ def __init__(
180185
181186 # Initialize completer.
182187 self .smart_completion = c ["main" ].as_bool ("smart_completion" )
183- self .completer = main_module . SQLCompleter (
188+ self .completer = SQLCompleter (
184189 self .smart_completion , supported_formats = self .main_formatter .supported_formats , keyword_casing = keyword_casing
185190 )
186191 self ._completer_lock = threading .Lock ()
@@ -195,17 +200,17 @@ def __init__(
195200 self .register_special_commands ()
196201
197202 # Load .mylogin.cnf if it exists.
198- mylogin_cnf_path = main_module . get_mylogin_cnf_path ()
203+ mylogin_cnf_path = get_mylogin_cnf_path ()
199204 if mylogin_cnf_path :
200- mylogin_cnf = main_module . open_mylogin_cnf (mylogin_cnf_path )
205+ mylogin_cnf = open_mylogin_cnf (mylogin_cnf_path )
201206 if mylogin_cnf_path and mylogin_cnf :
202207 # .mylogin.cnf gets read last, even if defaults_file is specified.
203208 self .cnf_files .append (mylogin_cnf )
204209 elif mylogin_cnf_path and not mylogin_cnf :
205210 # There was an error reading the login path file.
206211 print ("Error: Unable to read login path file." )
207212
208- self .my_cnf = main_module . read_config_files (self .cnf_files , list_values = False )
213+ self .my_cnf = read_config_files (self .cnf_files , list_values = False )
209214 ensure_my_cnf_sections (self .my_cnf )
210215 prompt_cnf = self .read_my_cnf (self .my_cnf , ["prompt" ])["prompt" ]
211216 configure_prompt_state (self , c , prompt , prompt_cnf , toolbar_format )
@@ -220,6 +225,4 @@ def close(self) -> None:
220225 self .sqlexecute .close ()
221226
222227 def run_cli (self ) -> None :
223- from mycli import main as main_module
224-
225- main_module .main_repl (self )
228+ repl_package .main_repl (self )
0 commit comments