Repository: kedro-org/kedro
Pull request: Don't include requirements only needed for example pipeline
## Description
<!-- Why was this PR created? -->
context: #3386 

## Development notes
<!-- What have you changed, and how has this been tested? -->

- Updated `utils.py` to remove `seaborn` and `scikit-learn` and the extras from `kedro-datasets`
- Updated requirements and toml to `Path` parameter types
- Updated release notes


## Developer Certificate of Origin
We need all contributions to comply with the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). All commits must be signed off by including a `Signed-off-by` line in the commit message. [See our wiki for guidance](https://github.com/kedro-org/kedro/wiki/Guidelines-for-contributing-developers/).

If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.

## Checklist

- [x] Read the [contributing](https://github.com/kedro-org/kedro/blob/main/CONTRIBUTING.md) guidelines
- [x] Signed off each commit with a [Developer Certificate of Origin (DCO)](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-the-commit-signoff-policy-for-your-repository)
- [x] Opened this PR as a 'Draft Pull Request' if it is work-in-progress
- [ ] Updated the documentation to reflect the code changes
- [x] Added a description of this change in the [`RELEASE.md`](https://github.com/kedro-org/kedro/blob/main/RELEASE.md) file
- [ ] Added tests to cover my changes
- [x] Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team


Problem statement:
Don't include requirements only needed for example pipeline
### Description
With the tools selection flow requirements get added but the following are only needed for running the example pipeline and also get included if the user doesn't want the example:

- seaborn
- scikit-learn
- kedro-datasets[....] the problem here is not `kedro-dataset` itself, but the preselected specific datasets e.g. `ExcelDataset`.

Hints from issue discussion:

Commit message: Merge branch 'main' into dev/remove-requirements-when-no-examples

Patch to review:
diff --git a/RELEASE.md b/RELEASE.md
index 401d6efc3a..18f4f18d23 100644
--- a/RELEASE.md
+++ b/RELEASE.md
@@ -3,6 +3,7 @@
 ## Major features and improvements
 
 ## Bug fixes and other changes
+* Removed example pipeline requirements when examples are not selected in `tools`.
 
 ## Breaking changes to the API
 
diff --git a/kedro/templates/project/hooks/utils.py b/kedro/templates/project/hooks/utils.py
index 1f2deb799e..b1c8eef484 100644
--- a/kedro/templates/project/hooks/utils.py
+++ b/kedro/templates/project/hooks/utils.py
@@ -15,6 +15,9 @@
 # Configuration key for documentation dependencies
 docs_pyproject_requirements = ["project.optional-dependencies"]  # For pyproject.toml
 
+# Requirements for example pipelines
+example_pipeline_requirements = "seaborn~=0.12.1\nscikit-learn~=1.0\n"
+
 
 # Helper Functions
 def _remove_from_file(file_path: Path, content_to_remove: str) -> None:
@@ -141,13 +144,36 @@ def _remove_pyspark_viz_starter_files(is_viz: bool, python_package_name: str) ->
     _remove_file(test_pipeline_path)
 
 
-def setup_template_tools(selected_tools_list: str, requirements_file_path: str, pyproject_file_path: str, python_package_name: str, example_pipeline: str) -> None:
-    """Setup the templates according to the choice of tools.
+def _remove_extras_from_kedro_datasets(file_path: Path) -> None:
+    """Remove all extras from kedro-datasets in the requirements file.
+
+    Args:
+        file_path (Path): The path of the requirements file.
+    """
+    with open(file_path, 'r') as file:
+        lines = file.readlines()
+
+    new_lines = []
+    for line in lines:
+        if 'kedro-datasets[' in line:
+            # Remove the extras by keeping only the part before the '['
+            new_line = line.split('[')[0] + '\n'
+            new_lines.append(new_line)
+        else:
+            new_lines.append(line)
+
+    with open(file_path, 'w') as file:
+        file.writelines(new_lines)
+
+
+def setup_template_tools(selected_tools_list: str, requirements_file_path: Path, pyproject_file_path: Path,
+                         python_package_name: str, example_pipeline: str) -> None:
+    """Set up the templates according to the choice of tools.
 
     Args:
         selected_tools_list (str): A string contains the selected tools.
-        requirements_file_path (str): The path of the `requiremenets.txt` in the template.
-        pyproject_file_path (str): The path of the `pyproject.toml` in the template
+        requirements_file_path (Path): The path of the `requiremenets.txt` in the template.
+        pyproject_file_path (Path): The path of the `pyproject.toml` in the template
         python_package_name (str): The name of the python package.
         example_pipeline (str): 'True' if example pipeline was selected
     """
@@ -172,6 +198,10 @@ def setup_template_tools(selected_tools_list: str, requirements_file_path: str,
 
     if ("PySpark" in selected_tools_list or "Kedro Viz" in selected_tools_list) and example_pipeline != "True":
         _remove_pyspark_viz_starter_files("Kedro Viz" in selected_tools_list, python_package_name)
+        # Remove requirements used by example pipelines
+        _remove_from_file(requirements_file_path, example_pipeline_requirements)
+        _remove_extras_from_kedro_datasets(requirements_file_path)
+
 
 def sort_requirements(requirements_file_path: Path) -> None:
     """Sort the requirements.txt file alphabetically and write it back to the file.


Code review comments:
diff_hunk: @@ -141,13 +144,36 @@ def _remove_pyspark_viz_starter_files(is_viz: bool, python_package_name: str) ->
     _remove_file(test_pipeline_path)
 
 
-def setup_template_tools(selected_tools_list: str, requirements_file_path: str, pyproject_file_path: str, python_package_name: str, example_pipeline: str) -> None:
-    """Setup the templates according to the choice of tools.
+def _remove_extras_from_kedro_datasets(file_path: Path) -> None:
+    """Remove all extras from kedro-datasets in the requirements file.
+
+    Args:
+        file_path (Path): The path of the requirements file.
+    """
+    with open(file_path, 'r') as file:
+        lines = file.readlines()
+
+    new_lines = []
path: kedro/templates/project/hooks/utils.py
text: @user1:
Thanks for PR, @author ! I have a small question, is lines a List? If yes why you are creating a new List new_lines and copying, not just modifying 1 row in list variable?

@author:
Yes lines is a list, It was for clarity but can amend for simplification. 

@author:
Simplified.

diff_hunk: @@ -141,13 +144,36 @@ def _remove_pyspark_viz_starter_files(is_viz: bool, python_package_name: str) ->
     _remove_file(test_pipeline_path)
 
 
-def setup_template_tools(selected_tools_list: str, requirements_file_path: str, pyproject_file_path: str, python_package_name: str, example_pipeline: str) -> None:
-    """Setup the templates according to the choice of tools.
+def _remove_extras_from_kedro_datasets(file_path: Path) -> None:
+    """Remove all extras from kedro-datasets in the requirements file.
+
+    Args:
+        file_path (Path): The path of the requirements file.
+    """
+    with open(file_path, 'r') as file:
+        lines = file.readlines()
+
+    new_lines = []
+    for line in lines:
+        if 'kedro-datasets[' in line:
+            # Remove the extras by keeping only the part before the '['
+            new_line = line.split('[')[0] + '\n'
path: kedro/templates/project/hooks/utils.py
text: @user1:
you are removing version on the end, is it ok?

@author:
Good spot made a change to keep it.