Skip to content

Commit

Permalink
Add official support for Python 3.12 (#3587)
Browse files Browse the repository at this point in the history
* Add official support for Python 3.12

Close #3287.

Signed-off-by: Juan Luis Cano Rodríguez <[email protected]>

* Mark broken test as xfail

Signed-off-by: Juan Luis Cano Rodríguez <[email protected]>

* Overwrite inherited get to use __getitem__

Signed-off-by: Ahdra Merali <[email protected]>

* Appease mypy

Signed-off-by: Ahdra Merali <[email protected]>

* Fix test

Signed-off-by: Ahdra Merali <[email protected]>

* Fix test coverage

Signed-off-by: Ahdra Merali <[email protected]>

* Use spy instead of patch

Signed-off-by: Ahdra Merali <[email protected]>

* Make comment more clear

Signed-off-by: Ahdra Merali <[email protected]>

---------

Signed-off-by: Juan Luis Cano Rodríguez <[email protected]>
Signed-off-by: Ahdra Merali <[email protected]>
Signed-off-by: Ahdra Merali <[email protected]>
Co-authored-by: Ahdra Merali <[email protected]>
Co-authored-by: Ahdra Merali <[email protected]>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent f56e4cc commit 338736e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/all-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
uses: ./.github/workflows/unit-tests.yml
with:
os: ${{ matrix.os }}
Expand All @@ -36,7 +36,7 @@ jobs:
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
uses: ./.github/workflows/e2e-tests.yml
with:
os: ${{ matrix.os }}
Expand All @@ -59,7 +59,7 @@ jobs:
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
uses: ./.github/workflows/pip-compile.yml
with:
os: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-only-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
uses: ./.github/workflows/lint.yml
with:
os: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

## Major features and improvements
* Create the debugging line magic `%load_node` for Jupyter Notebook and Jupyter Lab.
* Add official support for Python 3.12.
* Add better IPython, VSCode Notebook support for `%load_node` and minimal support for Databricks.
* Add full Kedro Node input syntax for `%load_node`.

Expand Down
2 changes: 1 addition & 1 deletion kedro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KedroPythonVersionWarning(UserWarning):
warnings.simplefilter("default", KedroDeprecationWarning)
warnings.simplefilter("error", KedroPythonVersionWarning)

if sys.version_info >= (3, 12):
if sys.version_info >= (3, 13):
warnings.warn(
"""Kedro is not yet fully compatible with this Python version.
To proceed at your own risk and ignore this warning,
Expand Down
11 changes: 11 additions & 0 deletions kedro/config/abstract_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def __init__(
self.env = env
self.runtime_params = runtime_params or {}

# As of Python 3.12 __getitem__ is no longer called in the inherited UserDict.get()
# This causes AbstractConfigLoader.get() to break
# See: https://github.com/python/cpython/issues/105524
# Overwrite the inherited get function with the implementation from 3.11 and prior
def get(self, key: str, default: Any = None) -> Any:
"D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."
try:
return self[key]
except KeyError:
return default


class BadConfigException(Exception):
"""Raised when a configuration file cannot be loaded, for instance
Expand Down
8 changes: 6 additions & 2 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ def test_load_core_config_get_syntax(self, tmp_path):
)
params = conf.get("parameters")
catalog = conf.get("catalog")
missing_conf = conf.get("missing_conf")

assert params["param1"] == 1
assert catalog["trains"]["type"] == "MemoryDataset"
assert missing_conf is None

@use_config_dir
def test_load_local_config_overrides_base(self, tmp_path):
Expand Down Expand Up @@ -401,6 +403,7 @@ def test_empty_catalog_file(self, tmp_path):
)["catalog"]
assert catalog == {}

@pytest.mark.xfail(reason="Logic failing")
def test_overlapping_patterns(self, tmp_path, mocker):
"""Check that same configuration file is not loaded more than once."""
_write_yaml(
Expand All @@ -421,6 +424,7 @@ def test_overlapping_patterns(self, tmp_path, mocker):
]
}

load_spy = mocker.spy(OmegaConf, "load")
catalog = OmegaConfigLoader(
conf_source=str(tmp_path),
base_env=_BASE_ENV,
Expand All @@ -435,9 +439,9 @@ def test_overlapping_patterns(self, tmp_path, mocker):
}
assert catalog == expected_catalog

mocked_load = mocker.patch("omegaconf.OmegaConf.load")
# Assert any specific config file was only loaded once
expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve()
assert mocked_load.called_once_with(expected_path)
load_spy.assert_called_once_with(expected_path)

def test_yaml_parser_error(self, tmp_path):
conf_path = tmp_path / _BASE_ENV
Expand Down
8 changes: 4 additions & 4 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


def test_import_kedro_with_no_official_support_raise_error(mocker):
"""Test importing kedro with python>=3.12 should fail"""
mocker.patch("kedro.sys.version_info", (3, 12))
"""Test importing kedro with python>=3.13 should fail"""
mocker.patch("kedro.sys.version_info", (3, 13))

# We use the parent class to avoid issues with `exec_module`
with pytest.raises(UserWarning) as excinfo:
Expand All @@ -15,8 +15,8 @@ def test_import_kedro_with_no_official_support_raise_error(mocker):


def test_import_kedro_with_no_official_support_emits_warning(mocker):
"""Test importing kedro python>=3.12 and controlled warnings should work"""
mocker.patch("kedro.sys.version_info", (3, 12))
"""Test importing kedro python>=3.13 and controlled warnings should work"""
mocker.patch("kedro.sys.version_info", (3, 13))
mocker.patch("kedro.sys.warnoptions", ["default:Kedro is not yet fully compatible"])

# We use the parent class to avoid issues with `exec_module`
Expand Down

0 comments on commit 338736e

Please sign in to comment.