From 3f39cd3ae2c1d90d0fae6049ae16087f9ecebb94 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 12:48:29 -0300 Subject: [PATCH 01/39] attempt to configure fallback logger Signed-off-by: lrcouto --- .../conf/logging.yml | 9 +-------- kedro/framework/project/default_logging.yml | 12 ++++++++++- kedro/logging.py | 20 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml index 984cac5069..97dfd9d9e6 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -23,13 +23,6 @@ handlers: encoding: utf8 delay: True - rich: - class: kedro.logging.RichHandler - rich_tracebacks: True - # Advance options for customisation. - # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration - # tracebacks_show_locals: False - loggers: kedro: level: INFO @@ -38,4 +31,4 @@ loggers: level: INFO root: - handlers: [rich] + handlers: [rich, console] diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index 87fae8a25c..a3ff952217 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -2,6 +2,10 @@ version: 1 disable_existing_loggers: False +formatters: + simple: + format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + handlers: rich: class: kedro.logging.RichHandler @@ -10,9 +14,15 @@ handlers: # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration # tracebacks_show_locals: False + console: + class: logging.StreamHandler + level: INFO + formatter: simple + stream: ext://sys.stdout + loggers: kedro: level: INFO root: - handlers: [rich] + handlers: [rich, console] diff --git a/kedro/logging.py b/kedro/logging.py index 72d85d41c5..b64005db7c 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,21 +1,21 @@ -""" -This module contains a logging handler class which produces coloured logs and tracebacks. -""" - import logging import sys from pathlib import Path from typing import Any import click -import rich.logging -import rich.pretty -import rich.traceback + +try: + import rich.logging + import rich.pretty + import rich.traceback +except ImportError: + rich = None from kedro.utils import _is_databricks -class RichHandler(rich.logging.RichHandler): +class RichHandler(logging.StreamHandler if rich is None else rich.logging.RichHandler): """Identical to rich's logging handler but with a few extra behaviours: * warnings issued by the `warnings` module are redirected to logging * pretty printing is enabled on the Python REPL (including IPython and Jupyter) @@ -30,6 +30,10 @@ class RichHandler(rich.logging.RichHandler): """ def __init__(self, *args: Any, **kwargs: Any): + if rich is None: + super().__init__(stream=sys.stdout) + return + super().__init__(*args, **kwargs) logging.captureWarnings(True) rich.pretty.install() From 80f0ff2c6fe64dbb1d7c8890f45858b967dde003 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 14:40:01 -0300 Subject: [PATCH 02/39] Set up fallback for logging on the logging function itself Signed-off-by: lrcouto --- .../{{ cookiecutter.repo_name }}/conf/logging.yml | 2 +- kedro/framework/project/default_logging.yml | 12 +----------- kedro/logging.py | 3 +-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml index 97dfd9d9e6..9c29a22308 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -31,4 +31,4 @@ loggers: level: INFO root: - handlers: [rich, console] + handlers: [rich] diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index a3ff952217..87fae8a25c 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -2,10 +2,6 @@ version: 1 disable_existing_loggers: False -formatters: - simple: - format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" - handlers: rich: class: kedro.logging.RichHandler @@ -14,15 +10,9 @@ handlers: # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration # tracebacks_show_locals: False - console: - class: logging.StreamHandler - level: INFO - formatter: simple - stream: ext://sys.stdout - loggers: kedro: level: INFO root: - handlers: [rich, console] + handlers: [rich] diff --git a/kedro/logging.py b/kedro/logging.py index b64005db7c..980b798a56 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,10 +1,9 @@ import logging +import click import sys from pathlib import Path from typing import Any -import click - try: import rich.logging import rich.pretty From 8c07db1e28cc9b231faa5a2f239c307aff331b22 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 15:11:09 -0300 Subject: [PATCH 03/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index 980b798a56..b64005db7c 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,9 +1,10 @@ import logging -import click import sys from pathlib import Path from typing import Any +import click + try: import rich.logging import rich.pretty From 6c666895e51fb9ff6b441fddd04f98fabbbcd34c Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 15:28:12 -0300 Subject: [PATCH 04/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index b64005db7c..bedcaeeb25 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -10,7 +10,7 @@ import rich.pretty import rich.traceback except ImportError: - rich = None + rich: Any = None from kedro.utils import _is_databricks From bfbb1f1b448943ef75df725675faab6a8d272726 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:43:40 -0300 Subject: [PATCH 05/39] Update kedro/logging.py Co-authored-by: Sajid Alam <90610031+SajidAlamQB@users.noreply.github.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- kedro/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index bedcaeeb25..41d060a4f0 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -9,8 +9,9 @@ import rich.logging import rich.pretty import rich.traceback + RICH = True except ImportError: - rich: Any = None + RICH = False from kedro.utils import _is_databricks From 2038792bd086f017d59d0b0bc8b2758d3eb53592 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Tue, 30 Apr 2024 12:06:54 -0300 Subject: [PATCH 06/39] Changes to rich variable on logging Signed-off-by: lrcouto --- kedro/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index 41d060a4f0..c1cf187f66 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -31,7 +31,7 @@ class RichHandler(logging.StreamHandler if rich is None else rich.logging.RichHa """ def __init__(self, *args: Any, **kwargs: Any): - if rich is None: + if RICH is False: super().__init__(stream=sys.stdout) return From 5b857112e9483c9e64a23f36b83fff6ea3351221 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 2 May 2024 11:17:56 -0300 Subject: [PATCH 07/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kedro/logging.py b/kedro/logging.py index c1cf187f66..45f06c03b4 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -9,6 +9,7 @@ import rich.logging import rich.pretty import rich.traceback + RICH = True except ImportError: RICH = False From b75327ddc1c9e4c8fff26cbc5a45fcfd8fbf6ebf Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 12:48:29 -0300 Subject: [PATCH 08/39] attempt to configure fallback logger Signed-off-by: lrcouto --- .../conf/logging.yml | 9 +-------- kedro/framework/project/default_logging.yml | 12 ++++++++++- kedro/logging.py | 20 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml index 984cac5069..97dfd9d9e6 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -23,13 +23,6 @@ handlers: encoding: utf8 delay: True - rich: - class: kedro.logging.RichHandler - rich_tracebacks: True - # Advance options for customisation. - # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration - # tracebacks_show_locals: False - loggers: kedro: level: INFO @@ -38,4 +31,4 @@ loggers: level: INFO root: - handlers: [rich] + handlers: [rich, console] diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index 87fae8a25c..a3ff952217 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -2,6 +2,10 @@ version: 1 disable_existing_loggers: False +formatters: + simple: + format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + handlers: rich: class: kedro.logging.RichHandler @@ -10,9 +14,15 @@ handlers: # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration # tracebacks_show_locals: False + console: + class: logging.StreamHandler + level: INFO + formatter: simple + stream: ext://sys.stdout + loggers: kedro: level: INFO root: - handlers: [rich] + handlers: [rich, console] diff --git a/kedro/logging.py b/kedro/logging.py index 72d85d41c5..b64005db7c 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,21 +1,21 @@ -""" -This module contains a logging handler class which produces coloured logs and tracebacks. -""" - import logging import sys from pathlib import Path from typing import Any import click -import rich.logging -import rich.pretty -import rich.traceback + +try: + import rich.logging + import rich.pretty + import rich.traceback +except ImportError: + rich = None from kedro.utils import _is_databricks -class RichHandler(rich.logging.RichHandler): +class RichHandler(logging.StreamHandler if rich is None else rich.logging.RichHandler): """Identical to rich's logging handler but with a few extra behaviours: * warnings issued by the `warnings` module are redirected to logging * pretty printing is enabled on the Python REPL (including IPython and Jupyter) @@ -30,6 +30,10 @@ class RichHandler(rich.logging.RichHandler): """ def __init__(self, *args: Any, **kwargs: Any): + if rich is None: + super().__init__(stream=sys.stdout) + return + super().__init__(*args, **kwargs) logging.captureWarnings(True) rich.pretty.install() From de86e8d6f90554efdf970f4d434436fb3de92cd4 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 14:40:01 -0300 Subject: [PATCH 09/39] Set up fallback for logging on the logging function itself Signed-off-by: lrcouto --- .../{{ cookiecutter.repo_name }}/conf/logging.yml | 2 +- kedro/framework/project/default_logging.yml | 12 +----------- kedro/logging.py | 3 +-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml index 97dfd9d9e6..9c29a22308 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -31,4 +31,4 @@ loggers: level: INFO root: - handlers: [rich, console] + handlers: [rich] diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index a3ff952217..87fae8a25c 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -2,10 +2,6 @@ version: 1 disable_existing_loggers: False -formatters: - simple: - format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" - handlers: rich: class: kedro.logging.RichHandler @@ -14,15 +10,9 @@ handlers: # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration # tracebacks_show_locals: False - console: - class: logging.StreamHandler - level: INFO - formatter: simple - stream: ext://sys.stdout - loggers: kedro: level: INFO root: - handlers: [rich, console] + handlers: [rich] diff --git a/kedro/logging.py b/kedro/logging.py index b64005db7c..980b798a56 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,10 +1,9 @@ import logging +import click import sys from pathlib import Path from typing import Any -import click - try: import rich.logging import rich.pretty From 658d0c17d439cfa99b9d172d46e2dc2c3c588793 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 15:11:09 -0300 Subject: [PATCH 10/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index 980b798a56..b64005db7c 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -1,9 +1,10 @@ import logging -import click import sys from pathlib import Path from typing import Any +import click + try: import rich.logging import rich.pretty From 609a0c2cc0ddfa2031208adf60d47826a89aa610 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 24 Apr 2024 15:28:12 -0300 Subject: [PATCH 11/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index b64005db7c..bedcaeeb25 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -10,7 +10,7 @@ import rich.pretty import rich.traceback except ImportError: - rich = None + rich: Any = None from kedro.utils import _is_databricks From 99bd891e21ce12afdeb32de6990addf72644233a Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:43:40 -0300 Subject: [PATCH 12/39] Update kedro/logging.py Co-authored-by: Sajid Alam <90610031+SajidAlamQB@users.noreply.github.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- kedro/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index bedcaeeb25..41d060a4f0 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -9,8 +9,9 @@ import rich.logging import rich.pretty import rich.traceback + RICH = True except ImportError: - rich: Any = None + RICH = False from kedro.utils import _is_databricks From a15bdcda2d3642cad50bfab5f68808c2cf1feaaf Mon Sep 17 00:00:00 2001 From: lrcouto Date: Tue, 30 Apr 2024 12:06:54 -0300 Subject: [PATCH 13/39] Changes to rich variable on logging Signed-off-by: lrcouto --- kedro/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index 41d060a4f0..c1cf187f66 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -31,7 +31,7 @@ class RichHandler(logging.StreamHandler if rich is None else rich.logging.RichHa """ def __init__(self, *args: Any, **kwargs: Any): - if rich is None: + if RICH is False: super().__init__(stream=sys.stdout) return From e80d5146266e6631f3af9eb717bf2cd88fa53783 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 2 May 2024 11:17:56 -0300 Subject: [PATCH 14/39] Lint Signed-off-by: lrcouto --- kedro/logging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kedro/logging.py b/kedro/logging.py index c1cf187f66..45f06c03b4 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -9,6 +9,7 @@ import rich.logging import rich.pretty import rich.traceback + RICH = True except ImportError: RICH = False From f802384f7ba45292ede579e1f01b16904f152132 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Fri, 3 May 2024 01:11:28 -0300 Subject: [PATCH 15/39] adapt default logging Signed-off-by: lrcouto --- kedro/framework/project/default_logging.yml | 22 ++++++++++++++++++- kedro/logging.py | 2 +- .../conf/logging.yml | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index 87fae8a25c..a34d066835 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -2,7 +2,27 @@ version: 1 disable_existing_loggers: False +formatters: + simple: + format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + handlers: + console: + class: logging.StreamHandler + level: INFO + formatter: simple + stream: ext://sys.stdout + + info_file_handler: + class: logging.handlers.RotatingFileHandler + level: INFO + formatter: simple + filename: info.log + maxBytes: 10485760 # 10MB + backupCount: 20 + encoding: utf8 + delay: True + rich: class: kedro.logging.RichHandler rich_tracebacks: True @@ -15,4 +35,4 @@ loggers: level: INFO root: - handlers: [rich] + handlers: [rich, console] diff --git a/kedro/logging.py b/kedro/logging.py index 45f06c03b4..1bf07c41da 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -17,7 +17,7 @@ from kedro.utils import _is_databricks -class RichHandler(logging.StreamHandler if rich is None else rich.logging.RichHandler): +class RichHandler(logging.StreamHandler if RICH is False else rich.logging.RichHandler): """Identical to rich's logging handler but with a few extra behaviours: * warnings issued by the `warnings` module are redirected to logging * pretty printing is enabled on the Python REPL (including IPython and Jupyter) diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml index 1cf75396ab..843bdc3f50 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -40,4 +40,4 @@ loggers: level: INFO root: - handlers: [rich, info_file_handler] + handlers: [rich, console, info_file_handler] From 5061229bfedc388f45580a6ef0f56d3314f403c1 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Fri, 3 May 2024 10:18:25 -0300 Subject: [PATCH 16/39] Update kedro/logging.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Juan Luis Cano Rodríguez Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- kedro/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/logging.py b/kedro/logging.py index 1bf07c41da..17f17fc65c 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -17,7 +17,7 @@ from kedro.utils import _is_databricks -class RichHandler(logging.StreamHandler if RICH is False else rich.logging.RichHandler): +class RichHandler(logging.StreamHandler if not RICH else rich.logging.RichHandler): """Identical to rich's logging handler but with a few extra behaviours: * warnings issued by the `warnings` module are redirected to logging * pretty printing is enabled on the Python REPL (including IPython and Jupyter) From 7c731f3925c9306f980abb18f2eb4f09ff968f4c Mon Sep 17 00:00:00 2001 From: lrcouto Date: Mon, 6 May 2024 14:16:32 -0300 Subject: [PATCH 17/39] Create separate logging config file for rich Signed-off-by: lrcouto --- MANIFEST.in | 1 + docs/source/conf.py | 1 + kedro/framework/project/__init__.py | 11 ++++-- kedro/framework/project/default_logging.yml | 9 +---- kedro/framework/project/rich_logging.yml | 38 +++++++++++++++++++++ kedro/logging.py | 11 ++---- pyproject.toml | 2 +- 7 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 kedro/framework/project/rich_logging.yml diff --git a/MANIFEST.in b/MANIFEST.in index 3aaf04a960..86910941db 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include README.md include LICENSE.md include kedro/framework/project/default_logging.yml +include kedro/framework/project/rich_logging.yml include kedro/ipython/*.png include kedro/ipython/*.svg recursive-include kedro/templates * diff --git a/docs/source/conf.py b/docs/source/conf.py index 21b9d6c4b4..49c0f119a7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -234,6 +234,7 @@ # "anchor not found" but it's a valid selector for code examples "https://docs.delta.io/latest/delta-update.html#language-python", "https://github.com/kedro-org/kedro/blob/main/kedro/framework/project/default_logging.yml", + "https://github.com/kedro-org/kedro/blob/main/kedro/framework/project/rich_logging.yml", "https://github.com/kedro-org/kedro/blob/main/README.md#the-humans-behind-kedro", # "anchor not found" but is valid "https://opensource.org/license/apache2-0-php/", "https://docs.github.com/en/rest/overview/other-authentication-methods#via-username-and-password", diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index ea56f5d668..2de54835fe 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -217,9 +217,14 @@ class _ProjectLogging(UserDict): def __init__(self) -> None: """Initialise project logging. The path to logging configuration is given in environment variable KEDRO_LOGGING_CONFIG (defaults to default_logging.yml).""" - path = os.environ.get( - "KEDRO_LOGGING_CONFIG", Path(__file__).parent / "default_logging.yml" - ) + if importlib.util.find_spec("rich") is not None: + path = os.environ.get( + "KEDRO_LOGGING_CONFIG", Path(__file__).parent / "rich_logging.yml" + ) + else: + path = os.environ.get( + "KEDRO_LOGGING_CONFIG", Path(__file__).parent / "default_logging.yml" + ) logging_config = Path(path).read_text(encoding="utf-8") self.configure(yaml.safe_load(logging_config)) diff --git a/kedro/framework/project/default_logging.yml b/kedro/framework/project/default_logging.yml index a34d066835..27feb17542 100644 --- a/kedro/framework/project/default_logging.yml +++ b/kedro/framework/project/default_logging.yml @@ -23,16 +23,9 @@ handlers: encoding: utf8 delay: True - rich: - class: kedro.logging.RichHandler - rich_tracebacks: True - # Advance options for customisation. - # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration - # tracebacks_show_locals: False - loggers: kedro: level: INFO root: - handlers: [rich, console] + handlers: [console] diff --git a/kedro/framework/project/rich_logging.yml b/kedro/framework/project/rich_logging.yml new file mode 100644 index 0000000000..951bd92484 --- /dev/null +++ b/kedro/framework/project/rich_logging.yml @@ -0,0 +1,38 @@ +version: 1 + +disable_existing_loggers: False + +formatters: + simple: + format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + +handlers: + console: + class: logging.StreamHandler + level: INFO + formatter: simple + stream: ext://sys.stdout + + info_file_handler: + class: logging.handlers.RotatingFileHandler + level: INFO + formatter: simple + filename: info.log + maxBytes: 10485760 # 10MB + backupCount: 20 + encoding: utf8 + delay: True + + rich: + class: kedro.logging.RichHandler + rich_tracebacks: True + # Advance options for customisation. + # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration + # tracebacks_show_locals: False + +loggers: + kedro: + level: INFO + +root: + handlers: [rich] \ No newline at end of file diff --git a/kedro/logging.py b/kedro/logging.py index 1bf07c41da..8a03030285 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -9,15 +9,14 @@ import rich.logging import rich.pretty import rich.traceback - - RICH = True except ImportError: - RICH = False + pass + from kedro.utils import _is_databricks -class RichHandler(logging.StreamHandler if RICH is False else rich.logging.RichHandler): +class RichHandler(rich.logging.RichHandler): """Identical to rich's logging handler but with a few extra behaviours: * warnings issued by the `warnings` module are redirected to logging * pretty printing is enabled on the Python REPL (including IPython and Jupyter) @@ -32,10 +31,6 @@ class RichHandler(logging.StreamHandler if RICH is False else rich.logging.RichH """ def __init__(self, *args: Any, **kwargs: Any): - if RICH is False: - super().__init__(stream=sys.stdout) - return - super().__init__(*args, **kwargs) logging.captureWarnings(True) rich.pretty.install() diff --git a/pyproject.toml b/pyproject.toml index 57bf2dfaf7..5c95338700 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "build>=0.7.0", "cachetools>=4.1", "click>=4.0", - "cookiecutter>=2.1.1,<3.0", + "cookiecutter==2.2.0", "dynaconf>=3.1.2,<4.0", "fsspec>=2021.4", "gitpython>=3.0", From a29220c7e146c962c98ee72648cbc50691e4bd29 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Mon, 6 May 2024 14:35:29 -0300 Subject: [PATCH 18/39] Hello linter my old friend Signed-off-by: lrcouto --- kedro/framework/project/rich_logging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/framework/project/rich_logging.yml b/kedro/framework/project/rich_logging.yml index 951bd92484..b541bc1e79 100644 --- a/kedro/framework/project/rich_logging.yml +++ b/kedro/framework/project/rich_logging.yml @@ -35,4 +35,4 @@ loggers: level: INFO root: - handlers: [rich] \ No newline at end of file + handlers: [rich] From f43c72ce3a39b244963b5eb60cd25a6af5ccd0d0 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Mon, 6 May 2024 15:17:10 -0300 Subject: [PATCH 19/39] Alternative for rich in kedro ipython Signed-off-by: lrcouto --- kedro/ipython/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index 182ff403f1..ae154c1e15 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -5,6 +5,7 @@ from __future__ import annotations +import importlib import inspect import logging import os @@ -18,8 +19,12 @@ from IPython.core.getipython import get_ipython from IPython.core.magic import needs_local_scope, register_line_magic from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring -from rich.console import Console -from rich.syntax import Syntax + +try: + from rich.console import Console + from rich.syntax import Syntax +except ImportError: + pass from kedro.framework.cli import load_entry_points from kedro.framework.cli.project import CONF_SOURCE_HELP, PARAMS_ARG_HELP @@ -281,8 +286,12 @@ def _create_cell_with_text(text: str, is_jupyter: bool = True) -> None: def _print_cells(cells: list[str]) -> None: for cell in cells: - Console().print("") - Console().print(Syntax(cell, "python", theme="monokai", line_numbers=False)) + if importlib.util.find_spec("rich") is not None: + Console().print("") + Console().print(Syntax(cell, "python", theme="monokai", line_numbers=False)) + else: + print("") # noqa: T201 + print(cell) # noqa: T201 def _load_node(node_name: str, pipelines: _ProjectPipelines) -> list[str]: From 838902389cf552213c24eab91c756884507d0e6c Mon Sep 17 00:00:00 2001 From: lrcouto Date: Mon, 6 May 2024 16:39:45 -0300 Subject: [PATCH 20/39] Remove unnecessary try/except block Signed-off-by: lrcouto --- kedro/framework/project/__init__.py | 17 +++++++++-------- kedro/logging.py | 11 +++-------- .../conf/logging.yml | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index 2de54835fe..3cf7da00f4 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -217,14 +217,15 @@ class _ProjectLogging(UserDict): def __init__(self) -> None: """Initialise project logging. The path to logging configuration is given in environment variable KEDRO_LOGGING_CONFIG (defaults to default_logging.yml).""" - if importlib.util.find_spec("rich") is not None: - path = os.environ.get( - "KEDRO_LOGGING_CONFIG", Path(__file__).parent / "rich_logging.yml" - ) - else: - path = os.environ.get( - "KEDRO_LOGGING_CONFIG", Path(__file__).parent / "default_logging.yml" - ) + path = os.environ.get( + "KEDRO_LOGGING_CONFIG", + Path(__file__).parent + / ( + "rich_logging.yml" + if importlib.util.find_spec("rich") + else "default_logging.yml" + ), + ) logging_config = Path(path).read_text(encoding="utf-8") self.configure(yaml.safe_load(logging_config)) diff --git a/kedro/logging.py b/kedro/logging.py index 8a03030285..83e8204fec 100644 --- a/kedro/logging.py +++ b/kedro/logging.py @@ -4,14 +4,9 @@ from typing import Any import click - -try: - import rich.logging - import rich.pretty - import rich.traceback -except ImportError: - pass - +import rich.logging +import rich.pretty +import rich.traceback from kedro.utils import _is_databricks diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml index 843bdc3f50..9f201d59fc 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -40,4 +40,4 @@ loggers: level: INFO root: - handlers: [rich, console, info_file_handler] + handlers: [rich] From 1ea51e87635b2a85e70b696413b24153e5544e2b Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Tue, 7 May 2024 12:06:27 -0300 Subject: [PATCH 21/39] Update pyproject.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Juan Luis Cano Rodríguez Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5c95338700..4b69b5f035 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "build>=0.7.0", "cachetools>=4.1", "click>=4.0", - "cookiecutter==2.2.0", + "cookiecutter==2.2.0", # 2.3 onwards depends on rich, which we want to avoid "dynaconf>=3.1.2,<4.0", "fsspec>=2021.4", "gitpython>=3.0", From 3663bdf2ffe861673f6bdc59e8cf8e7fc620dbc4 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 8 May 2024 14:20:46 -0300 Subject: [PATCH 22/39] Resolve merge conflict Signed-off-by: lrcouto --- kedro/framework/project/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index 4e16cbd059..feea809732 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -224,15 +224,15 @@ def __init__(self) -> None: # Check if the default logging configuration exists default_logging_path = Path("conf/logging.yml") if not default_logging_path.exists(): - path = os.environ.get( + default_logging_path = os.environ.get( "KEDRO_LOGGING_CONFIG", Path(__file__).parent / ( - "rich_logging.yml" - if importlib.util.find_spec("rich") - else "default_logging.yml" - ), - ) + "rich_logging.yml" + if importlib.util.find_spec("rich") + else "default_logging.yml" + ), + ) # Use the user path if available, otherwise, use the default path if user_logging_path and Path(user_logging_path).exists(): From 16e05b896e02981f84440582d18077dd7b10d3a5 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 8 May 2024 14:31:42 -0300 Subject: [PATCH 23/39] Lint Signed-off-by: lrcouto --- kedro/framework/project/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index feea809732..3866d7d6c0 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -224,14 +224,13 @@ def __init__(self) -> None: # Check if the default logging configuration exists default_logging_path = Path("conf/logging.yml") if not default_logging_path.exists(): - default_logging_path = os.environ.get( - "KEDRO_LOGGING_CONFIG", - Path(__file__).parent - / ( + default_logging_path = Path( + os.environ.get( + "KEDRO_LOGGING_CONFIG", "rich_logging.yml" if importlib.util.find_spec("rich") - else "default_logging.yml" - ), + else "default_logging.yml", + ) ) # Use the user path if available, otherwise, use the default path From 269ec9801a0f25d7aa0020fb1a6c2bbb18765264 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 8 May 2024 14:52:32 -0300 Subject: [PATCH 24/39] Fix config file paths Signed-off-by: lrcouto --- kedro/framework/project/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index 3866d7d6c0..7cfd2a9957 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -227,9 +227,9 @@ def __init__(self) -> None: default_logging_path = Path( os.environ.get( "KEDRO_LOGGING_CONFIG", - "rich_logging.yml" + Path(__file__).parent / "rich_logging.yml" if importlib.util.find_spec("rich") - else "default_logging.yml", + else Path(__file__).parent / "default_logging.yml", ) ) From 235a5bf97fb8856cc5d60e9a608df2ae73865402 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Thu, 9 May 2024 12:51:27 -0300 Subject: [PATCH 25/39] Update kedro/ipython/__init__.py Co-authored-by: Deepyaman Datta Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- kedro/ipython/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index ae154c1e15..6727aa3a22 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -21,10 +21,10 @@ from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring try: - from rich.console import Console - from rich.syntax import Syntax + import rich.console as rich_console + import rich.syntax as rich_syntax except ImportError: - pass + rich_console = rich_syntax = None from kedro.framework.cli import load_entry_points from kedro.framework.cli.project import CONF_SOURCE_HELP, PARAMS_ARG_HELP From c1f6cbfb71f0b1d3069a1373ade52f02fb87cfb6 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Thu, 9 May 2024 12:51:38 -0300 Subject: [PATCH 26/39] Update kedro/ipython/__init__.py Co-authored-by: Deepyaman Datta Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- kedro/ipython/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index 6727aa3a22..0204914a81 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -286,9 +286,9 @@ def _create_cell_with_text(text: str, is_jupyter: bool = True) -> None: def _print_cells(cells: list[str]) -> None: for cell in cells: - if importlib.util.find_spec("rich") is not None: - Console().print("") - Console().print(Syntax(cell, "python", theme="monokai", line_numbers=False)) + if rich_console is not None: + rich_console.Console().print("") + rich_console.Console().print(rich_syntax.Syntax(cell, "python", theme="monokai", line_numbers=False)) else: print("") # noqa: T201 print(cell) # noqa: T201 From 210b0edbabbe7adddac1a268a92c1c30a05f882a Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 9 May 2024 17:25:27 -0300 Subject: [PATCH 27/39] Prevent kedro ipython from reimporting rich multiple times Signed-off-by: lrcouto --- kedro/ipython/__init__.py | 10 +++++++--- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index 0204914a81..27fb6e473b 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -24,7 +24,7 @@ import rich.console as rich_console import rich.syntax as rich_syntax except ImportError: - rich_console = rich_syntax = None + pass from kedro.framework.cli import load_entry_points from kedro.framework.cli.project import CONF_SOURCE_HELP, PARAMS_ARG_HELP @@ -44,6 +44,8 @@ FunctionParameters = MappingProxyType +RICH = True if importlib.util.find_spec("rich") is not None else False + def load_ipython_extension(ipython: Any) -> None: """ @@ -286,9 +288,11 @@ def _create_cell_with_text(text: str, is_jupyter: bool = True) -> None: def _print_cells(cells: list[str]) -> None: for cell in cells: - if rich_console is not None: + if RICH is True: rich_console.Console().print("") - rich_console.Console().print(rich_syntax.Syntax(cell, "python", theme="monokai", line_numbers=False)) + rich_console.Console().print( + rich_syntax.Syntax(cell, "python", theme="monokai", line_numbers=False) + ) else: print("") # noqa: T201 print(cell) # noqa: T201 diff --git a/pyproject.toml b/pyproject.toml index 791e6d1ac7..a23260a6b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "build>=0.7.0", "cachetools>=4.1", "click>=4.0", - "cookiecutter==2.2.0", # 2.3 onwards depends on rich, which we want to avoid + "cookiecutter>=2.1.1,<2.3", # 2.3 onwards depends on rich, which we want to avoid "dynaconf>=3.1.2,<4.0", "fsspec>=2021.4", "gitpython>=3.0", From 98f8e4d00e7435eaf7ec291ca5b912fb81cdbba1 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 9 May 2024 19:02:33 -0300 Subject: [PATCH 28/39] Logging config Signed-off-by: lrcouto --- kedro/framework/project/rich_logging.yml | 22 +------------------ .../conf/logging.yml | 2 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/kedro/framework/project/rich_logging.yml b/kedro/framework/project/rich_logging.yml index b541bc1e79..13fc456e60 100644 --- a/kedro/framework/project/rich_logging.yml +++ b/kedro/framework/project/rich_logging.yml @@ -2,27 +2,7 @@ version: 1 disable_existing_loggers: False -formatters: - simple: - format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" - handlers: - console: - class: logging.StreamHandler - level: INFO - formatter: simple - stream: ext://sys.stdout - - info_file_handler: - class: logging.handlers.RotatingFileHandler - level: INFO - formatter: simple - filename: info.log - maxBytes: 10485760 # 10MB - backupCount: 20 - encoding: utf8 - delay: True - rich: class: kedro.logging.RichHandler rich_tracebacks: True @@ -35,4 +15,4 @@ loggers: level: INFO root: - handlers: [rich] + handlers: [rich] \ No newline at end of file diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml index 9f201d59fc..a234445ef5 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -40,4 +40,4 @@ loggers: level: INFO root: - handlers: [rich] + handlers: [rich, info_file_handler] \ No newline at end of file From 191bba75b4a13d39e62b66aff6bbf02d4438dbdb Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 9 May 2024 22:34:58 -0300 Subject: [PATCH 29/39] Change test config Signed-off-by: lrcouto --- .../{{ cookiecutter.repo_name }}/conf/logging.yml | 7 +++++++ kedro/framework/project/rich_logging.yml | 2 +- .../project/{{ cookiecutter.repo_name }}/conf/logging.yml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml index 9c29a22308..984cac5069 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -23,6 +23,13 @@ handlers: encoding: utf8 delay: True + rich: + class: kedro.logging.RichHandler + rich_tracebacks: True + # Advance options for customisation. + # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration + # tracebacks_show_locals: False + loggers: kedro: level: INFO diff --git a/kedro/framework/project/rich_logging.yml b/kedro/framework/project/rich_logging.yml index 13fc456e60..87fae8a25c 100644 --- a/kedro/framework/project/rich_logging.yml +++ b/kedro/framework/project/rich_logging.yml @@ -15,4 +15,4 @@ loggers: level: INFO root: - handlers: [rich] \ No newline at end of file + handlers: [rich] diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml index a234445ef5..1cf75396ab 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -40,4 +40,4 @@ loggers: level: INFO root: - handlers: [rich, info_file_handler] \ No newline at end of file + handlers: [rich, info_file_handler] From b44fb5ef3c07d8a1c8cd32099121bc000a82028a Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 9 May 2024 23:19:36 -0300 Subject: [PATCH 30/39] Remove ' yEs ' tests Signed-off-by: lrcouto --- tests/framework/cli/test_starters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index b4fb54d552..73fd44c7ee 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -1119,7 +1119,7 @@ def test_invalid_tools_range(self, fake_kedro_cli, input): message = f"'{input}' is an invalid range for project tools.\nPlease ensure range values go from smaller to larger." assert message in result.output - @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs", " yeS "]) + @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs"]) def test_valid_example(self, fake_kedro_cli, example_pipeline): result = CliRunner().invoke( fake_kedro_cli, @@ -1285,7 +1285,7 @@ def test_invalid_tools_flag_combination(self, fake_kedro_cli, input): in result.output ) - @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs", " yeS "]) + @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs"]) def test_valid_example(self, fake_kedro_cli, example_pipeline): """Test project created from config.""" config = { From c4c8aa751511b4b1283365c5c2f4b92b73a2e08f Mon Sep 17 00:00:00 2001 From: lrcouto Date: Fri, 10 May 2024 00:19:57 -0300 Subject: [PATCH 31/39] Tests to cover ipython changes Signed-off-by: lrcouto --- tests/ipython/test_ipython.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/ipython/test_ipython.py b/tests/ipython/test_ipython.py index 333dc5e80e..2e0c295140 100644 --- a/tests/ipython/test_ipython.py +++ b/tests/ipython/test_ipython.py @@ -457,9 +457,20 @@ def test_load_node_with_ipython(self, mocker, ipython, run_env): ipython.magic("load_node dummy_node") spy.assert_called_once() - @pytest.mark.parametrize("run_env", ["databricks", "colab", "dummy"]) - def test_load_node_with_other(self, mocker, ipython, run_env): + @pytest.mark.parametrize( + "run_env, rich_installed", + [ + ("databricks", True), + ("databricks", False), + ("colab", True), + ("colab", False), + ("dummy", True), + ("dummy", False), + ], + ) + def test_load_node_with_other(self, mocker, ipython, run_env, rich_installed): mocker.patch("kedro.ipython._find_kedro_project") + mocker.patch("kedro.ipython.RICH", rich_installed) mocker.patch("kedro.ipython._load_node", return_value=["cell1", "cell2"]) mocker.patch("kedro.ipython._guess_run_environment", return_value=run_env) spy = mocker.spy(kedro.ipython, "_print_cells") From d76124f426356168aeb0a9635ddc1e20dbce7e4d Mon Sep 17 00:00:00 2001 From: lrcouto Date: Fri, 10 May 2024 00:50:31 -0300 Subject: [PATCH 32/39] Add test for import Signed-off-by: lrcouto --- tests/ipython/test_ipython.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/ipython/test_ipython.py b/tests/ipython/test_ipython.py index 2e0c295140..ecb19294c9 100644 --- a/tests/ipython/test_ipython.py +++ b/tests/ipython/test_ipython.py @@ -516,3 +516,41 @@ def test_format_node_inputs_text_multiple_inputs(self): def test_format_node_inputs_text_no_catalog_load(self): # Test with no catalog.load() statements if input_params_dict is None assert _format_node_inputs_text(None) is None + + +def _example_function(): + try: + import rich.console as rich_console + import rich.syntax as rich_syntax + + return rich_console, rich_syntax + except ImportError: + return None, None + + +def test_imports_success(mocker): + # Mocking successful imports + mock_console = mocker.MagicMock(name="mock_console") + mock_syntax = mocker.MagicMock(name="mock_syntax") + mocker.patch("rich.console", mock_console) + mocker.patch("rich.syntax", mock_syntax) + + # Calling the function + console, syntax = _example_function() + + # Asserting that the function returned the mocked objects + assert console == mock_console + assert syntax == mock_syntax + + +def test_import_failure(mocker): + # Mocking import failure + mocker.patch("rich.console", None) + mocker.patch("rich.syntax", None) + + # Calling the function + console, syntax = _example_function() + + # Asserting that the function returned None for both imports + assert console is None + assert syntax is None From 9dbaf94e28f29a86a58af80f6ffd4f25ed880779 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Fri, 10 May 2024 01:00:32 -0300 Subject: [PATCH 33/39] Ignore test coverage on import try/except Signed-off-by: lrcouto --- kedro/ipython/__init__.py | 2 +- tests/ipython/test_ipython.py | 38 ----------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index 27fb6e473b..e822489caf 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -23,7 +23,7 @@ try: import rich.console as rich_console import rich.syntax as rich_syntax -except ImportError: +except ImportError: # pragma: no cover pass from kedro.framework.cli import load_entry_points diff --git a/tests/ipython/test_ipython.py b/tests/ipython/test_ipython.py index ecb19294c9..2e0c295140 100644 --- a/tests/ipython/test_ipython.py +++ b/tests/ipython/test_ipython.py @@ -516,41 +516,3 @@ def test_format_node_inputs_text_multiple_inputs(self): def test_format_node_inputs_text_no_catalog_load(self): # Test with no catalog.load() statements if input_params_dict is None assert _format_node_inputs_text(None) is None - - -def _example_function(): - try: - import rich.console as rich_console - import rich.syntax as rich_syntax - - return rich_console, rich_syntax - except ImportError: - return None, None - - -def test_imports_success(mocker): - # Mocking successful imports - mock_console = mocker.MagicMock(name="mock_console") - mock_syntax = mocker.MagicMock(name="mock_syntax") - mocker.patch("rich.console", mock_console) - mocker.patch("rich.syntax", mock_syntax) - - # Calling the function - console, syntax = _example_function() - - # Asserting that the function returned the mocked objects - assert console == mock_console - assert syntax == mock_syntax - - -def test_import_failure(mocker): - # Mocking import failure - mocker.patch("rich.console", None) - mocker.patch("rich.syntax", None) - - # Calling the function - console, syntax = _example_function() - - # Asserting that the function returned None for both imports - assert console is None - assert syntax is None From 0c63233200143f751da12fefc9ce3e976833a6ba Mon Sep 17 00:00:00 2001 From: lrcouto Date: Fri, 10 May 2024 01:02:26 -0300 Subject: [PATCH 34/39] Lint Signed-off-by: lrcouto --- kedro/ipython/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index e822489caf..8cb454a6ad 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -23,7 +23,7 @@ try: import rich.console as rich_console import rich.syntax as rich_syntax -except ImportError: # pragma: no cover +except ImportError: # pragma: no cover pass from kedro.framework.cli import load_entry_points From 671917d84f86f1d400f6b20ebbad505045968be8 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Tue, 14 May 2024 11:44:06 -0300 Subject: [PATCH 35/39] Unpin cookiecutter version Signed-off-by: lrcouto --- pyproject.toml | 2 +- tests/framework/cli/test_starters.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 22804407c5..57bf2dfaf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "build>=0.7.0", "cachetools>=4.1", "click>=4.0", - "cookiecutter>=2.1.1,<2.3", # 2.3 onwards depends on rich, which we want to avoid + "cookiecutter>=2.1.1,<3.0", "dynaconf>=3.1.2,<4.0", "fsspec>=2021.4", "gitpython>=3.0", diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index 73fd44c7ee..5d00fa5401 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -1119,7 +1119,7 @@ def test_invalid_tools_range(self, fake_kedro_cli, input): message = f"'{input}' is an invalid range for project tools.\nPlease ensure range values go from smaller to larger." assert message in result.output - @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs"]) + @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs", " yEs "]) def test_valid_example(self, fake_kedro_cli, example_pipeline): result = CliRunner().invoke( fake_kedro_cli, @@ -1285,7 +1285,7 @@ def test_invalid_tools_flag_combination(self, fake_kedro_cli, input): in result.output ) - @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs"]) + @pytest.mark.parametrize("example_pipeline", ["y", "n", "N", "YEs", " yEs "]) def test_valid_example(self, fake_kedro_cli, example_pipeline): """Test project created from config.""" config = { From eb3b151f4b4bf54bec879c0d652d33de866a1211 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 15 May 2024 00:18:15 -0300 Subject: [PATCH 36/39] Add changes to documentation Signed-off-by: lrcouto --- RELEASE.md | 1 + .../configuration/configuration_basics.md | 18 ++++++++++++++++++ docs/source/faq/faq.md | 1 + 3 files changed, 20 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index 620abccf2c..77f2c880e7 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,7 @@ # Upcoming Release 0.19.6 ## Major features and improvements +* It is now possible to uninstall the `rich` library from Kedro and have it maintain functionality. ## Bug fixes and other changes * User defined catch-all dataset factory patterns now override the default pattern provided by the runner. diff --git a/docs/source/configuration/configuration_basics.md b/docs/source/configuration/configuration_basics.md index 6cb7bb7336..d940ee61f2 100644 --- a/docs/source/configuration/configuration_basics.md +++ b/docs/source/configuration/configuration_basics.md @@ -241,3 +241,21 @@ Customise the configuration loader arguments in `settings.py` as follows if your ```python CONFIG_LOADER_ARGS = {"default_run_env": "base"} ``` + +### How to use Kedro without the rich library + +If you prefer not to have the `rich` library in your Kedro project, you have the option to uninstall it. However, it's important to note that versions of the `cookiecutter` library above 2.3 have a dependency on rich. You will need to downgrade `cookiecutter` to a version below 2.3 to have Kedro work without `rich`. + +To uninstall the rich library, run: + +```bash +pip uninstall rich +``` + +To downgrade cookiecutter to a version that does not require rich, you can specify a version below 2.3. For example: + +```bash +pip install cookiecutter==2.2.0 +``` + +These changes will affect the visual appearance and formatting of Kedro's logging, prompts, and the output of the `kedro ipython` command. While using a version of `cookiecutter` below 2.3, the appearance of the prompts will be plain even with `rich` installed. diff --git a/docs/source/faq/faq.md b/docs/source/faq/faq.md index 6193d96740..fdb9502bff 100644 --- a/docs/source/faq/faq.md +++ b/docs/source/faq/faq.md @@ -35,6 +35,7 @@ This is a growing set of technical FAQs. The [product FAQs on the Kedro website] * [How do I specify additional configuration environments](../configuration/configuration_basics.md#how-to-specify-additional-configuration-environments)? * [How do I change the default overriding configuration environment](../configuration/configuration_basics.md#how-to-change-the-default-overriding-environment)? * [How do I use only one configuration environment](../configuration/configuration_basics.md#how-to-use-only-one-configuration-environment)? +* [How do I use Kedro without the rich library](../configuration/configuration_basics.md#how-to-use-kedro-without-the-rich-library)? ### Advanced topics From 0f0214f6eae02a98ed24a7a5136f6aca880f2a36 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Wed, 15 May 2024 15:08:38 -0300 Subject: [PATCH 37/39] Update RELEASE.md Co-authored-by: Merel Theisen <49397448+merelcht@users.noreply.github.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- RELEASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 77f2c880e7..e1de485c02 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,7 +1,7 @@ # Upcoming Release 0.19.6 ## Major features and improvements -* It is now possible to uninstall the `rich` library from Kedro and have it maintain functionality. +* It is now possible to use Kedro without having `rich` installed. ## Bug fixes and other changes * User defined catch-all dataset factory patterns now override the default pattern provided by the runner. From 192d34983f4b74c77d89eeb3f107069955a00652 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 15 May 2024 17:09:43 -0300 Subject: [PATCH 38/39] Change RICH variable name to RICH_INTALLED Signed-off-by: lrcouto --- kedro/ipython/__init__.py | 4 ++-- tests/ipython/test_ipython.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/ipython/__init__.py b/kedro/ipython/__init__.py index 8cb454a6ad..ee487582e8 100644 --- a/kedro/ipython/__init__.py +++ b/kedro/ipython/__init__.py @@ -44,7 +44,7 @@ FunctionParameters = MappingProxyType -RICH = True if importlib.util.find_spec("rich") is not None else False +RICH_INSTALLED = True if importlib.util.find_spec("rich") is not None else False def load_ipython_extension(ipython: Any) -> None: @@ -288,7 +288,7 @@ def _create_cell_with_text(text: str, is_jupyter: bool = True) -> None: def _print_cells(cells: list[str]) -> None: for cell in cells: - if RICH is True: + if RICH_INSTALLED is True: rich_console.Console().print("") rich_console.Console().print( rich_syntax.Syntax(cell, "python", theme="monokai", line_numbers=False) diff --git a/tests/ipython/test_ipython.py b/tests/ipython/test_ipython.py index 2e0c295140..1ab436e3a9 100644 --- a/tests/ipython/test_ipython.py +++ b/tests/ipython/test_ipython.py @@ -470,7 +470,7 @@ def test_load_node_with_ipython(self, mocker, ipython, run_env): ) def test_load_node_with_other(self, mocker, ipython, run_env, rich_installed): mocker.patch("kedro.ipython._find_kedro_project") - mocker.patch("kedro.ipython.RICH", rich_installed) + mocker.patch("kedro.ipython.RICH_INSTALLED", rich_installed) mocker.patch("kedro.ipython._load_node", return_value=["cell1", "cell2"]) mocker.patch("kedro.ipython._guess_run_environment", return_value=run_env) spy = mocker.spy(kedro.ipython, "_print_cells") From 8c15acb1e74f970c0151ec671eec7c923a34b0a5 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 16 May 2024 16:12:05 -0300 Subject: [PATCH 39/39] Add info about uninstalling rich on logging doc page Signed-off-by: lrcouto --- docs/source/logging/index.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/source/logging/index.md b/docs/source/logging/index.md index 7b0226e3bd..b38679a3c7 100644 --- a/docs/source/logging/index.md +++ b/docs/source/logging/index.md @@ -194,3 +194,21 @@ You must provide a value for both `COLUMNS` and `LINES` even if you only wish to ## How to enable rich logging in Jupyter Rich also formats the logs in JupyterLab and Jupyter Notebook. The size of the output console does not adapt to your window but can be controlled through the `JUPYTER_COLUMNS` and `JUPYTER_LINES` environment variables. The default values (115 and 100 respectively) should be suitable for most users, but if you require a different output console size then you should alter the values of `JUPYTER_COLUMNS` and `JUPYTER_LINES`. + +### How to use logging without the rich library + +If you prefer not to have the `rich` library in your Kedro project, you have the option to uninstall it. However, it's important to note that versions of the `cookiecutter` library above 2.3 have a dependency on rich. You will need to downgrade `cookiecutter` to a version below 2.3 to have Kedro work without `rich`. + +To uninstall the rich library, run: + +```bash +pip uninstall rich +``` + +To downgrade cookiecutter to a version that does not require rich, you can specify a version below 2.3. For example: + +```bash +pip install cookiecutter==2.2.0 +``` + +These changes will affect the visual appearance and formatting of Kedro's logging, prompts, and the output of the `kedro ipython` command. While using a version of `cookiecutter` below 2.3, the appearance of the prompts will be plain even with `rich` installed.