Repository: kedro-org/kedro
File: kedro/templates/project/hooks/utils.py (Python)

Code before:
        python_package_name (str): The name of the python package.
        example_pipeline (str): 'True' if example pipeline was selected
    """
    if "Linting" not in selected_tools_list:
        _remove_from_file(requirements_file_path, lint_requirements)
        _remove_from_toml(pyproject_file_path, lint_pyproject_requirements)

    if "Testing" not in selected_tools_list:
        _remove_from_file(requirements_file_path, test_requirements)
        _remove_from_toml(pyproject_file_path, test_pyproject_requirements)
        _remove_dir(current_dir / "tests")

    if "Logging" not in selected_tools_list:
        _remove_file(current_dir / "conf/logging.yml")

    if "Documentation" not in selected_tools_list:
        _remove_from_toml(pyproject_file_path, docs_pyproject_requirements)
        _remove_dir(current_dir / "docs")

    if "Data Structure" not in selected_tools_list and example_pipeline != "True":
        _remove_dir(current_dir / "data")

    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.

    Args:
        requirements_file_path (Path): The path to the `requirements.txt` file.
    """
    with open(requirements_file_path, 'r') as requirements:
        lines = requirements.readlines()

    lines = [line.strip() for line in lines]
    lines.sort()
    sorted_content = '\n'.join(lines)

    with open(requirements_file_path, 'w') as requirements:
        requirements.write(sorted_content)


Review comment (suggestion):
We also need to do this when there's no example chosen, but also no `pyspark` or viz right? https://github.com/kedro-org/kedro-starters/blob/main/spaceflights-pandas/%7B%7B%20cookiecutter.repo_name%20%7D%7D/requirements.txt

Code after:
        example_pipeline (str): 'True' if example pipeline was selected
    """
    if "Linting" not in selected_tools_list:
        _remove_from_file(requirements_file_path, lint_requirements)
        _remove_from_toml(pyproject_file_path, lint_pyproject_requirements)

    if "Testing" not in selected_tools_list:
        _remove_from_file(requirements_file_path, test_requirements)
        _remove_from_toml(pyproject_file_path, test_pyproject_requirements)
        _remove_dir(current_dir / "tests")

    if "Logging" not in selected_tools_list:
        _remove_file(current_dir / "conf/logging.yml")

    if "Documentation" not in selected_tools_list:
        _remove_from_toml(pyproject_file_path, docs_pyproject_requirements)
        _remove_dir(current_dir / "docs")

    if "Data Structure" not in selected_tools_list and example_pipeline != "True":
        _remove_dir(current_dir / "data")

    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.

    Args:
        requirements_file_path (Path): The path to the `requirements.txt` file.
    """
    with open(requirements_file_path, 'r') as requirements:
        lines = requirements.readlines()

    lines = [line.strip() for line in lines]
    lines.sort()
    sorted_content = '\n'.join(lines)

    with open(requirements_file_path, 'w') as requirements:
        requirements.write(sorted_content)