Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing kedro.runners enables Rich logging #3985

Open
astrojuanlu opened this issue Jul 3, 2024 · 2 comments
Open

Importing kedro.runners enables Rich logging #3985

astrojuanlu opened this issue Jul 3, 2024 · 2 comments

Comments

@astrojuanlu
Copy link
Member

Description

image

Context

Steps to Reproduce

  1. Do a logging.warning("ANY MESSAGE") on a notebook to see that it's formatted as plain text
  2. import kedro.runners
  3. Repeat logging.warning("ANY MESSAGE") and observe the formatting has changed

Expected Result

Actual Result

I didn't expect imports to have such side effects.

Also, I don't think there's a way to revert it: Textualize/rich#2461 so I need to resort to hacks.

@merelcht
Copy link
Member

merelcht commented Jul 5, 2024

I've done some digging and the issue at first seems to come from the import:from kedro.framework.hooks.manager import _NullPluginManager. But then I moved that out and I got some more info when doing import kedro.runner:

[07/05/24 14:50:03] INFO     Using                                                                  [__init__.py](file:///Users/Merel_Theisen/anaconda3/envs/kedro/lib/python3.11/site-packages/kedro/framework/project/__init__.py):[246](file:///Users/Merel_Theisen/anaconda3/envs/kedro/lib/python3.11/site-packages/kedro/framework/project/__init__.py#246)
                             '/Users/Merel_Theisen/anaconda3/envs/kedro/lib/python3.11/site-package                
                             s/kedro/framework/project/rich_logging.yml' as logging configuration.

So it seems that logging is configured when you import the runner. I've also checked that this doesn't happen when importing e.g. DataCatalog or the configloaders.

It seems that this comes from the ParallelRunner where we directly import LOGGING which triggers the logging configuration
I tested this by removing ParallelRunner completely and the references to it in kedro.runner.__init__.py and can see that rich doesn't get triggered when it's all removed.

It looks like it comes from:

from kedro.framework.hooks.manager import (
_create_hook_manager,
_register_hooks,
_register_hooks_entry_points,
)
from kedro.framework.project import settings

Which flows into:

from kedro.framework.context import KedroContext

to:

from kedro.framework.project import settings

which seems to lead to:

LOGGING = _ProjectLogging()

So it turns out it is both the import to _NullPluginManager as well as the imports inside ParallelRunner to hooks and project settings. Eventually it all boils down to the logging being configured when project settings are imported.

@astrojuanlu
Copy link
Member Author

Fixing this issue is very difficult, the code is quite nested, and we prefer to wait until we tackle the root cause of the issues we have with rich, see #3967 (comment)

I'm leaving this open for visibility but we aren't doing anything about it for now. If somebody finds an easy way to fix it, PRs welcome.

@astrojuanlu astrojuanlu added the Issue: Bug Report 🐞 Bug that needs to be fixed label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants