diff --git a/features/environment.py b/features/environment.py index b2b859590b..b7a9e738aa 100644 --- a/features/environment.py +++ b/features/environment.py @@ -8,6 +8,11 @@ import venv from pathlib import Path +try: + import tomllib +except ImportError: + import tomli as tomllib # type: ignore + from features.steps.sh_run import run _PATHS_TO_REMOVE: set[Path] = set() @@ -115,13 +120,33 @@ def _setup_minimal_env(context): def _install_project_requirements(context): - install_reqs = ( - Path( - "kedro/templates/project/{{ cookiecutter.repo_name }}/dev-requirements.txt" - ) - .read_text(encoding="utf-8") - .splitlines() - ) + # HACK: Dev requirements of the project are stored in pyproject.toml, + # but the file cannot be directly loaded because it's a cookicutter template, + # so we read only the part that we need + with open( + "kedro/templates/project/{{ cookiecutter.repo_name }}/pyproject.toml", + encoding="utf-8", + ) as pyproject_fh: + _buffer = [] + while True: + try: + line = next(pyproject_fh) + except StopIteration as exc: + raise RuntimeError("Error while reading project dependencies") from exc + + if line.startswith("[project.optional-dependencies]"): + _buffer.append(line) + for line in pyproject_fh: + if line.startswith("["): + break + + _buffer.append(line) + break + + _meta = tomllib.loads("\n".join(_buffer)) + install_reqs = _meta["project"]["optional-dependencies"]["dev"] + # EOH + install_reqs = [req for req in install_reqs if "{" not in req] install_reqs.append(".[pandas.CSVDataSet]") call([context.pip, "install", *install_reqs], env=context.env) diff --git a/test_requirements.txt b/test_requirements.txt index cc448d41f7..4fc4d73783 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -59,6 +59,7 @@ SQLAlchemy~=1.2 tables~=3.6.0; platform_system == "Windows" and python_version<'3.9' tables~=3.6; platform_system != "Windows" tensorflow~=2.0 +tomli~=2.0.1; python_version < '3.11' triad>=0.6.7, <1.0 trufflehog~=2.1 xlsxwriter~=1.0