Repository: QuantConnect/lean-cli (python)

Issue:
Revisit global variables state handling
Global variables settings like the following are not working as expected. For example this container instance is not being shared with the rest of the library at runtime => using --verbose is not enabling debug mode globally
<img width="778" alt="Image" src="https://github.com/user-attachments/assets/74d64660-11b1-4641-bc9e-a23f2bc3beab" />

Pull request description:
Fix Logging with --verbose for container.data_downloader.update_database_files()
This PR ensures that the --verbose option is processed before container.data_downloader.update_database_files() is executed, enabling debug logging for this method. Previously, debug messages in update_database_files() were lost because --verbose was applied after the method ran. Now, debug logs will be visible when --verbose is used, improving visibility into the data download process.

Closes #546

Patch:
diff --git a/lean/click.py b/lean/click.py
index 94c98af..9b87258 100644
--- a/lean/click.py
+++ b/lean/click.py
@@ -183,6 +183,7 @@ class LeanCommand(Command):
         self.context_settings["allow_extra_args"] = allow_unknown_options
 
     def invoke(self, ctx: Context):
+        container.data_downloader.update_database_files()
         if self._requires_lean_config:
             lean_config_manager = container.lean_config_manager
             try:
diff --git a/lean/container.py b/lean/container.py
index e2cc918..67fa067 100644
--- a/lean/container.py
+++ b/lean/container.py
@@ -211,5 +211,4 @@ class Container:
         return engine_image, container_module_version, project_config
 
 
-container = Container()
-container.data_downloader.update_database_files()
+container = Container()
\ No newline at end of file


Test patch:
diff --git a/tests/commands/test_live.py b/tests/commands/test_live.py
index a7fea02..4dbc024 100644
--- a/tests/commands/test_live.py
+++ b/tests/commands/test_live.py
@@ -1240,23 +1240,25 @@ def test_live_deploy_with_different_brokerage_and_different_live_data_provider_a
     api_client = mock.MagicMock()
     create_lean_option(brokerage_name, data_provider_live_name, data_provider_historical_name, api_client)
 
+    # Filter method calls to include only 'modules.list_files' calls
+    filtered_calls = [call for call in api_client.method_calls if call[0] == 'modules.list_files']
     is_exists = []
     if brokerage_product_id is None and data_provider_historical_name != "Local":
-        assert len(api_client.method_calls) == 2
-        for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, data_provider_historical_id]):
+        assert len(api_client.method_calls) == 3
+        for m_c, id in zip(filtered_calls, [data_provider_live_product_id, data_provider_historical_id]):
             if id in m_c[1]:
                 is_exists.append(True)
         assert is_exists
         assert len(is_exists) == 1
     elif brokerage_product_id is None and data_provider_historical_name == "Local":
-        assert len(api_client.method_calls) == 1
-        if int(data_provider_live_product_id) in api_client.method_calls[0][1]:
+        assert len(api_client.method_calls) == 2
+        if int(data_provider_live_product_id) in filtered_calls[0][1]:
             is_exists.append(True)
         assert is_exists
         assert len(is_exists) == 1
     else:
-        assert len(api_client.method_calls) == 3
-        for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, data_provider_historical_id, brokerage_product_id]):
+        assert len(api_client.method_calls) == 4
+        for m_c, id in zip(filtered_calls, [data_provider_live_product_id, data_provider_historical_id, brokerage_product_id]):
             if id in f"{m_c[1]}":
                 is_exists.append(True)
         assert is_exists
@@ -1272,12 +1274,14 @@ def test_live_non_interactive_deploy_with_different_brokerage_and_different_live
     api_client = mock.MagicMock()
     create_lean_option(brokerage_name, data_provider_live_name, None, api_client)
 
-    assert len(api_client.method_calls) == 2
+    assert len(api_client.method_calls) == 3
+
+    # Filter method calls to include only 'modules.list_files' calls
+    filtered_calls = [call for call in api_client.method_calls if call[0] == 'modules.list_files']
     is_exists = []
-    for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, brokerage_product_id]):
+    for m_c, id in zip(filtered_calls, [data_provider_live_product_id, brokerage_product_id]):
         if id in m_c[1]:
             is_exists.append(True)
-
     assert is_exists
     assert len(is_exists) == 2
 
@@ -1309,7 +1313,7 @@ def test_live_non_interactive_deploy_paper_brokerage_different_live_data_provide
     api_client = mock.MagicMock()
     create_lean_option(brokerage_name, data_provider_live_name, None, api_client)
 
-    assert len(api_client.method_calls) == 1
+    assert len(api_client.method_calls) == 2
     for m_c in api_client.method_calls:
         if data_provider_live_product_id in str(m_c[1]):
             is_exist = True
diff --git a/tests/conftest.py b/tests/conftest.py
index c3a8f4c..0aad21c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -34,6 +34,12 @@ def initialize_container(docker_manager_to_use=None, lean_runner_to_use=None, ap
     api_client.organizations.get_all.return_value = [
         QCMinimalOrganization(id="abc", name="abc", type="type", ownerName="You", members=1, preferred=True)
     ]
+
+    # Configure download_public_file to return bytes
+    mock_csv_content = b"symbol,property\nAAPL,value\n"
+    mock_json_content = b'{"market": "hours"}'
+    api_client.data.download_public_file = mock.MagicMock(side_effect=[mock_csv_content, mock_json_content])
+
     if api_client_to_use:
         api_client = api_client_to_use