From c409d6874ed333eb48b5218d31e0ac1863458bac Mon Sep 17 00:00:00 2001 From: Merel Theisen <49397448+merelcht@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:06:38 +0100 Subject: [PATCH] Make packaged Kedro project work in interactive environment (#4026) * Make packaged kedro work in interactive environment Signed-off-by: Merel Theisen Signed-off-by: Merel Theisen <49397448+merelcht@users.noreply.github.com> Co-authored-by: ElenaKhaustova <157851531+ElenaKhaustova@users.noreply.github.com> --- RELEASE.md | 1 + .../src/{{ cookiecutter.python_package }}/__main__.py | 6 ++++++ .../src/{{ cookiecutter.python_package }}/__main__.py | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index 0df120a8c9..10b3e9a845 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,7 @@ # Upcoming Release 0.19.8 ## Major features and improvements +* Made default run entrypoint in `__main__.py` work in interactive environments such as IPyhon and Databricks. ## Bug fixes and other changes * Moved `_find_run_command()` and `_find_run_command_in_plugins()` from `__main__.py` in the project template to the framework itself. diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py b/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py index d951412ad1..041586456a 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py @@ -1,6 +1,8 @@ """{{ cookiecutter.project_name }} file for ensuring the package is executable as `{{ cookiecutter.repo_name }}` and `python -m {{ cookiecutter.python_package }}` """ + +import sys from pathlib import Path from kedro.framework.cli.utils import find_run_command @@ -10,6 +12,10 @@ def main(*args, **kwargs): package_name = Path(__file__).parent.name configure_project(package_name) + + interactive = hasattr(sys, 'ps1') + kwargs["standalone_mode"] = not interactive + run = find_run_command(package_name) run(*args, **kwargs) diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py index d951412ad1..49ae2b9506 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/__main__.py @@ -1,6 +1,7 @@ """{{ cookiecutter.project_name }} file for ensuring the package is executable as `{{ cookiecutter.repo_name }}` and `python -m {{ cookiecutter.python_package }}` """ +import sys from pathlib import Path from kedro.framework.cli.utils import find_run_command @@ -10,6 +11,10 @@ def main(*args, **kwargs): package_name = Path(__file__).parent.name configure_project(package_name) + + interactive = hasattr(sys, 'ps1') + kwargs["standalone_mode"] = not interactive + run = find_run_command(package_name) run(*args, **kwargs)