Repository: Galileo-Galilei/kedro-mlflow (language: python)

Issue:
Remove reload_kedro_mlflow line magic
## Description

The ``reload_kedro_mlflow`` line magic is used to expose a ``mlflow_client`` in jupyter notebooks automatically. 

## Context

- To my knowledge, this is not used by anyone. People are likely not aware that it exists. Please comment if you do.
- Whatever I do, [kedro will remove this entrypoint in 0.18.3](https://github.com/kedro-org/kedro/issues/878), so it will stop working. 

To avoid code debt, this will be removed in future versions, and will not be considered a breaking change.

## Possible Implementation

Remove: 
- the [entire ``extras`` folder](https://github.com/Galileo-Galilei/kedro-mlflow/tree/master/kedro_mlflow/extras)
- the [``setup.py`` entrypoint](https://github.com/Galileo-Galilei/kedro-mlflow/blob/73a78d89735328d6b4b78f98ce6436d07faad920/setup.py#L75-L77)
and all according tests



Discussion / hints:
Note for anyone who wants to access the mlflow client in a notebook:  loading the kedro extension will automatically creates a context, which setups mlflow. The ``_mlflow_client`` is a private attribute you can access directly:

```jupyter
%load_ext kedro.ipython
context.mlflow.server._mlflow_client
```

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0b87a79..0a84caef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,11 @@
 
 ### Fixed
 
--   :bug: `MlflowArtifactDataSet.load()` now correctly loads the artifact when both `artifact_path` and `run_id` arguments are specified. Previous fix in ``0.11.4`` did not work because when the file already exist locally, mlflow did not download it again so tests were incorrectly passing.   ([#362](https://github.com/Galileo-Galilei/kedro-mlflow/issues/362))
+-   :bug: `MlflowArtifactDataSet.load()` now correctly loads the artifact when both `artifact_path` and `run_id` arguments are specified. Previous fix in ``0.11.4`` did not work because when the file already exist locally, mlflow did not download it again so tests were incorrectly passing ([#362](https://github.com/Galileo-Galilei/kedro-mlflow/issues/362))
+
+### Removed
+
+-   :fire: :boom: Remove ``reload_kedro_mlflow`` line magic for notebook because kedro will deprecate the entrypoint in 0.18.3. It is still possible to access the mlflow client associated to the configuration in a notebook with ``context.mlflow.server._mlflow_client`` ([#349](https://github.com/Galileo-Galilei/kedro-mlflow/issues/349)). This is not considered as a breaking change since apparently no one uses it according to a [discussion with kedro's team](https://github.com/kedro-org/kedro/issues/878#issuecomment-1226545251)
 
 ## [0.11.4] - 2022-10-04
 
diff --git a/docs/source/06_interactive_use/01_notebook_use.md b/docs/source/06_interactive_use/01_notebook_use.md
index e5ef0286..f1bf4585 100644
--- a/docs/source/06_interactive_use/01_notebook_use.md
+++ b/docs/source/06_interactive_use/01_notebook_use.md
@@ -1,7 +1,7 @@
 # How to use `kedro-mlflow` in a notebook
 
 ```{important}
-You need to call ``pip install kedro_mlflow[extras]`` to access notebook functionalities.
+You need to install ``ipython`` to access notebook functionalities.
 ```
 
 ## Reminder on mlflow's limitations with interactive use
@@ -22,24 +22,26 @@ Open your notebook / ipython session with the Kedro CLI:
 kedro jupyter notebook
 ```
 
-Kedro [creates a bunch of global variables](https://kedro.readthedocs.io/en/latest/tools_integration/ipython.html#kedro-and-jupyter), including a `session` which are automatically accessible. It also registers some line_magic from plugins, including `%=reload_kedro_mlflow` from `kedro-mlflow`.
 
-In your first cell, launch:
-```
-%reload_kedro_mlflow
+Or if you are on JupyterLab,
+
+```notebook
+%load_ext kedro.ipython
 ```
 
-This automatically:
-- load and setup (create the tracking uri, export credentials...) the mlflow configuration of your `mlflow.yml`
+Kedro [creates a bunch of global variables](https://kedro.readthedocs.io/en/latest/tools_integration/ipython.html#kedro-and-jupyter), including a `session`, a ``context`` and a ``catalog`` which are automatically accessible.
+
+When the context was created, ``kedro-mlflow`` automatically:
+- loaded and setup (create the tracking uri, export credentials...) the mlflow configuration of your `mlflow.yml`
 - import ``mlflow`` which is now accessible in your notebook
-- Create a `mlflow_client` object with your mlflow server settings, which is now accessible in your notebook
 
-If you change your ``mlflow.yml``, re-execute this cell for the changes to take effect.
+If you change your ``mlflow.yml``, reload the kedro extension for the changes to take effect.
 
 ## Difference with running through the CLI
 
 - The DataSets `load` and `save` methods works as usual. You can call `catalog.save("my_artifact_dataset", data)` inside a cell, and your data will be logged in mlflow properly (assuming "my_artifact_dataset" is a `kedro_mlflow.io.MlflowArtifactDataSet`).
-- The `hooks` which setup configuration are only accessible if you run the session interactive, e.g.:
+- The `hooks` which automatically save all parameters/metrics/artifacts in mlflow will work if you run the session interactively, e.g.:
+
 ```python
 session.run(
     pipeline_name="my_ml_pipeline",
@@ -49,6 +51,7 @@ session.run(
 )
 ```
 but it is not very likely in a notebook.
+- if you need to interact manually with the mlflow server, you can use ``context.mlflow.server._mlflow_client``.
 
 ## Guidelines and best practices suggestions
 
diff --git a/kedro_mlflow/extras/__init__.py b/kedro_mlflow/extras/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/kedro_mlflow/extras/extensions/__init__.py b/kedro_mlflow/extras/extensions/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/kedro_mlflow/extras/extensions/ipython.py b/kedro_mlflow/extras/extensions/ipython.py
deleted file mode 100644
index 3ba26bd2..00000000
--- a/kedro_mlflow/extras/extensions/ipython.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import logging.config
-
-from IPython import get_ipython
-from kedro.framework.startup import bootstrap_project
-from mlflow.tracking import MlflowClient
-
-
-def reload_kedro_mlflow(line=None, local_ns=None):
-    metadata = bootstrap_project(
-        local_ns["project_path"]
-    )  # project_path is a global variable defined by init_kedro
-
-    mlflow_client = MlflowClient(
-        tracking_uri=local_ns["context"].mlflow.server.mlflow_tracking_uri
-    )
-    global_variables = {"mlflow_client": mlflow_client}
-    get_ipython().push(variables=global_variables)
-
-    global_variables_names = "\n- ".join(
-        [f"'{key}'" for key in global_variables.keys()]
-    )
-    logging.info("** Kedro project %s", str(metadata.project_name))
-    logging.info("Import mlflow in namespace")
-    logging.info("Setup mlflow configuration")
-    logging.info(f"Defined global variable(s):\n- {global_variables_names}")
diff --git a/setup.py b/setup.py
index 0d6614e0..a8793a32 100644
--- a/setup.py
+++ b/setup.py
@@ -59,22 +59,15 @@ def _parse_requirements(path, encoding="utf-8"):
             "pre-commit>=2.0.0,<3.0.0",
             "jupyter>=1.0.0,<2.0.0",
         ],
-        "extras": ["notebook>=6.0.0"],
     },
     author="Yolan Honoré-Rougé",
     entry_points={
         "kedro.project_commands": [
             "kedro_mlflow =  kedro_mlflow.framework.cli.cli:commands"
         ],
-        # "kedro.global_commands": [
-        #     "kedro_mlflow =  kedro_mlflow.framework.cli.cli:commands"
-        # ],
         "kedro.hooks": [
             "mlflow_hook = kedro_mlflow.framework.hooks.mlflow_hook:mlflow_hook",
         ],
-        "kedro.line_magic": [
-            "line_magic = kedro_mlflow.extras.extensions.ipython:reload_kedro_mlflow"
-        ],
     },
     zip_safe=False,
     keywords="kedro-plugin, mlflow, model versioning, model packaging, pipelines, machine learning, data pipelines, data science, data engineering",


Test patch:
diff --git a/tests/extras/__init__.py b/tests/extras/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/extras/extensions/__init__.py b/tests/extras/extensions/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/extras/extensions/test_ipython.py b/tests/extras/extensions/test_ipython.py
deleted file mode 100644
index 06c61845..00000000
--- a/tests/extras/extensions/test_ipython.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import pytest
-from kedro.framework.session.session import KedroSession
-from kedro.framework.startup import bootstrap_project
-
-from kedro_mlflow.extras.extensions.ipython import reload_kedro_mlflow
-
-
-@pytest.fixture(autouse=True)
-def mocked_logging(mocker):
-    # Disable logging.config.dictConfig in KedroSession._setup_logging as
-    # it changes logging.config and affects other unit tests
-    return mocker.patch("logging.config.dictConfig")
-
-
-def test_load_global_variables_in_ipython(mocker, kedro_project_with_mlflow_conf):
-
-    mock_ipython = mocker.patch("kedro_mlflow.extras.extensions.ipython.get_ipython")
-    mocker.patch("kedro.framework.session.session.KedroSession._setup_logging")
-
-    metadata = bootstrap_project(kedro_project_with_mlflow_conf)
-    with KedroSession.create(
-        metadata.package_name, project_path=metadata.project_path
-    ) as session:
-        context = session.load_context()
-        reload_kedro_mlflow(
-            line=None,
-            local_ns={"project_path": metadata.project_path, "context": context},
-        )
-
-    mock_ipython().push.assert_called_once_with(variables={"mlflow_client": mocker.ANY})