diff --git a/kedro/__init__.py b/kedro/__init__.py index be9febd329..de25eb79a4 100644 --- a/kedro/__init__.py +++ b/kedro/__init__.py @@ -3,4 +3,26 @@ configuration and pipeline assembly. """ +import sys +import warnings + __version__ = "0.18.11" + + +class KedroPythonVersionWarning(UserWarning): + """Custom class for warnings about incompatibilities with Python versions.""" + + pass + + +if not sys.warnoptions: + warnings.simplefilter("error", KedroPythonVersionWarning) + +if sys.version_info >= (3, 11): + warnings.warn( + """Kedro is not yet fully compatible with this Python version. +To proceed at your own risk and ignore this warning, +run Kedro with `python -W "default:Kedro is not yet fully compatible" -m kedro ...` +or set the PYTHONWARNINGS environment variable accordingly.""", + KedroPythonVersionWarning, + ) diff --git a/pyproject.toml b/pyproject.toml index ec06b75d5f..0421b726c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ {name = "Kedro"} ] description = "Kedro helps you build production-ready data and analytics pipelines" -requires-python = ">=3.7, <3.11" +requires-python = ">=3.7" keywords = [ "pipelines", "machine learning", diff --git a/tests/test_import.py b/tests/test_import.py new file mode 100644 index 0000000000..81436ecfc6 --- /dev/null +++ b/tests/test_import.py @@ -0,0 +1,27 @@ +import pytest + +import kedro + + +def test_import_kedro_with_no_official_support_raise_error(mocker): + """Test importing kedro with python>=3.11 should fail""" + mocker.patch("kedro.sys.version_info", (3, 11)) + + # We use the parent class to avoid issues with `exec_module` + with pytest.raises(UserWarning) as excinfo: + kedro.__loader__.exec_module(kedro) + + assert "Kedro is not yet fully compatible" in str(excinfo.value) + + +def test_import_kedro_with_no_official_support_emits_warning(mocker): + """Test importing kedro python>=3.11 and controlled warnings should work""" + mocker.patch("kedro.sys.version_info", (3, 11)) + mocker.patch("kedro.sys.warnoptions", ["default:Kedro is not yet fully compatible"]) + + # We use the parent class to avoid issues with `exec_module` + with pytest.warns(UserWarning) as record: + kedro.__loader__.exec_module(kedro) + + assert len(record) == 1 + assert "Kedro is not yet fully compatible" in record[0].message.args[0]