Skip to content

Commit

Permalink
Allow any version of Python (including 3.11) in metadata (#2742)
Browse files Browse the repository at this point in the history
* Allow any version of Python in metadata

See https://iscinumpy.dev/post/bound-version-constraints/#pinning-the-python-version-is-special,
and discussion in https://discuss.python.org/t/requires-python-upper-limits/12663?u=astrojuanlu,
as well as practical problems with leaving the version cap on in
#2270 (comment).

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>

* Add toggleable error if Python version is incompatible

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>

* temp commit

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* change gitpod

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* revert GitPod

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* add tests

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* Fix import tests

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>

---------

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Co-authored-by: Nok <nok.lam.chan@quantumblack.com>
  • Loading branch information
astrojuanlu and noklam authored Jul 11, 2023
1 parent 77a784c commit 7e8d9f4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
22 changes: 22 additions & 0 deletions kedro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 7e8d9f4

Please sign in to comment.