Skip to content

Commit 44817b8

Browse files
lrcoutomerelcht
andauthored
Update spaceflights tutorial and starter requirements for kedro-datasets optional dependencies (#3664)
* Update spaceflights tutorial and starter requirements Signed-off-by: lrcouto <laurarccouto@gmail.com> * fix e2e tests Signed-off-by: lrcouto <laurarccouto@gmail.com> * Fix e2e tests by distinguishing `kedro-datasets` dependency for different python versions (#3802) Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com> * Update docs/source/tutorial/tutorial_template.md Co-authored-by: Merel Theisen <49397448+merelcht@users.noreply.github.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --------- Signed-off-by: lrcouto <laurarccouto@gmail.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com> Co-authored-by: Merel Theisen <49397448+merelcht@users.noreply.github.com>
1 parent f8bdf13 commit 44817b8

8 files changed

Lines changed: 47 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ package: clean install
4646

4747
install-test-requirements:
4848
python -m pip install -U "pip>=21.2"
49-
pip install .[test]
49+
pip install -U .[test]
5050

5151
install-pre-commit:
5252
pre-commit install --install-hooks

docs/source/kedro_project_setup/dependencies.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ For example, your workflow might require the `pandas.ExcelDataset`, so to instal
4545
From `kedro-datasets` version 3.0.0 onwards, the names of the optional dataset-level dependencies have been normalised to follow [PEP 685](https://peps.python.org/pep-0685/). The '.' character has been replaced with a '-' character and the names are in lowercase. For example, if you had `kedro-datasets[pandas.ExcelDataset]` in your requirements file, it would have to be changed to `kedro-datasets[pandas-exceldataset]`.
4646
```
4747

48-
4948
## Reproducible environments
5049
To ensure that the project dependencies and the transitive dependencies are pinned to specific versions, use [`pip-tools`](https://pypi.org/project/pip-tools/) to compile `requirements.txt` file into a `requirements.lock` file.
5150
To install `pip-tools` in your virtual environment, run the following command:

docs/source/tutorial/tutorial_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pytest~=7.2
4848
4949
# Kedro dependencies and datasets to work with different data formats (including CSV, Excel, and Parquet)
5050
kedro~=0.19.0
51-
kedro-datasets[pandas.CSVDataset, pandas.ExcelDataset, pandas.ParquetDataset]>=1.1
51+
kedro-datasets[pandas-csvdataset, pandas-exceldataset, pandas-parquetdataset]>=3.0
5252
kedro-telemetry>=0.3.1
5353
kedro-viz~=6.0 # Visualise pipelines
5454

features/environment.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import shutil
77
import subprocess
8+
import sys
89
import tempfile
910
import venv
1011
from pathlib import Path
@@ -14,6 +15,7 @@
1415
_PATHS_TO_REMOVE: set[Path] = set()
1516

1617
FRESH_VENV_TAG = "fresh_venv"
18+
MINOR_PYTHON_38_VERSION = 8
1719

1820

1921
def call(cmd, env):
@@ -130,6 +132,11 @@ def _install_project_requirements(context):
130132
.splitlines()
131133
)
132134
install_reqs = [req for req in install_reqs if "{" not in req and "#" not in req]
133-
install_reqs.append("kedro-datasets[pandas.CSVDataset]")
135+
# For Python versions 3.9 and above we use the new dataset dependency format introduced in `kedro-datasets` 3.0.0
136+
if sys.version_info.minor > MINOR_PYTHON_38_VERSION:
137+
install_reqs.append("kedro-datasets[pandas-csvdataset]")
138+
# For Python 3.8 we use the older `kedro-datasets` dependency format
139+
else:
140+
install_reqs.append("kedro-datasets[pandas.CSVDataset]")
134141
call([context.pip, "install", *install_reqs], env=context.env)
135142
return context

features/steps/cli_steps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ def check_one_node_run(context, number):
554554
def check_correct_nodes_run(context, node):
555555
expected_log_line = f"Running node: {node}"
556556
stdout = context.result.stdout
557-
assert expected_log_line in stdout, (
557+
clean_logs = util.clean_up_log(stdout)
558+
assert expected_log_line in clean_logs, (
558559
"Expected the following message segment to be printed on stdout: "
559560
f"{expected_log_line},\nbut got {stdout}"
560561
)
@@ -595,7 +596,8 @@ def check_message_printed(context, msg):
595596
else:
596597
stdout = context.result.stdout
597598

598-
assert msg in stdout, (
599+
clean_logs = util.clean_up_log(stdout)
600+
assert msg in clean_logs, (
599601
"Expected the following message segment to be printed on stdout: "
600602
f"{msg},\nbut got {stdout}"
601603
)

features/steps/test_starter/{{ cookiecutter.repo_name }}/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ ipython>=8.10
33
jupyterlab>=3.0
44
notebook
55
kedro~={{ cookiecutter.kedro_version}}
6-
kedro-datasets[pandas.CSVDataset]
6+
kedro-datasets[pandas-csvdataset]; python_version >= "3.9"
7+
kedro-datasets[pandas.CSVDataset]<2.0.0; python_version < '3.9'
78
kedro-telemetry>=0.3.1
89
pytest-cov~=3.0
910
pytest-mock>=1.7.1, <2.0

features/steps/util.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,32 @@ def parse_csv(text: str) -> list[str]:
8383
List of string tokens
8484
"""
8585
return re.findall(r"\"(.+?)\"\s*,?", text)
86+
87+
88+
def clean_up_log(stdout: str) -> str:
89+
"""
90+
Cleans up log output by removing duplicate lines, extra whitespaces,
91+
and log levels (INFO, WARNING, ERROR) along with .py filenames.
92+
93+
Args:
94+
stdout (str): The log output to be cleaned.
95+
96+
Returns:
97+
str: Cleaned log output without unnecessary information.
98+
"""
99+
cleaned_lines = []
100+
already_extracted = set()
101+
102+
for line in stdout.split("\n"):
103+
if any(word in line for word in ["WARNING", "INFO", "ERROR"]):
104+
# Remove log levels and .py filenames
105+
cleaned_line = re.sub(r"\b(INFO|WARNING|ERROR)\b|\s+\w+\.py:\d+", "", line)
106+
cleaned_lines.append(cleaned_line.strip())
107+
already_extracted.add(line)
108+
elif line not in already_extracted:
109+
cleaned_lines.append(line)
110+
111+
cleaned_output = "\n".join(cleaned_lines)
112+
cleaned_output = re.sub(r"\s+", " ", cleaned_output)
113+
114+
return cleaned_output.strip()

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ test = [
6161
"jupyterlab_server>=2.11.1",
6262
"jupyterlab>=3,<5",
6363
"jupyter~=1.0",
64-
"kedro-datasets",
64+
"kedro-datasets; python_version >= '3.9'",
65+
"kedro-datasets<2.0.0; python_version < '3.9'",
6566
"mypy~=1.0",
6667
"pandas~=2.0",
6768
"pluggy>=1.0, <1.4", # pluggy 1.4 hide imports inside function and causing mocking issue

0 commit comments

Comments
 (0)