From ff1b91160db4cae1b2f8990515e94ff09dce792a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Morais?= <146729917+SMoraisAnsys@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:33:47 +0200 Subject: [PATCH] CHORE: Add warning on python version (#5050) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com> --- _unittest/test_warnings.py | 28 ++++++++++++++++------------ src/ansys/aedt/core/__init__.py | 17 +++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/_unittest/test_warnings.py b/_unittest/test_warnings.py index d21e62dbb89..b38edfa439a 100644 --- a/_unittest/test_warnings.py +++ b/_unittest/test_warnings.py @@ -27,24 +27,28 @@ import warnings from ansys.aedt.core import LATEST_DEPRECATED_PYTHON_VERSION +from ansys.aedt.core import WARNING_MESSAGE from ansys.aedt.core import deprecation_warning +VALID_PYTHON_VERSION = (LATEST_DEPRECATED_PYTHON_VERSION[0], LATEST_DEPRECATED_PYTHON_VERSION[1] + 1) + @patch.object(warnings, "warn") -def test_deprecation_warning(mock_warn): +def test_deprecation_warning_with_deprecated_python_version(mock_warn, monkeypatch): + monkeypatch.setattr(sys, "version_info", LATEST_DEPRECATED_PYTHON_VERSION) + + deprecation_warning() + + mock_warn.assert_called_once_with(WARNING_MESSAGE, FutureWarning) + + +@patch.object(warnings, "warn") +def test_deprecation_warning_with_valid_python_version(mock_warn, monkeypatch): + monkeypatch.setattr(sys, "version_info", VALID_PYTHON_VERSION) + deprecation_warning() - current_version = sys.version_info[:2] - if current_version <= LATEST_DEPRECATED_PYTHON_VERSION: - str_current_version = "{}.{}".format(*sys.version_info[:2]) - expected = ( - "Current python version ({}) is deprecated in PyAEDT. We encourage you " - "to upgrade to the latest version to benefit from the latest features " - "and security updates.".format(str_current_version) - ) - mock_warn.assert_called_once_with(expected, PendingDeprecationWarning) - else: - mock_warn.assert_not_called() + mock_warn.assert_not_called() @patch.object(warnings, "warn") diff --git a/src/ansys/aedt/core/__init__.py b/src/ansys/aedt/core/__init__.py index f4b3c2609e1..371d4562141 100644 --- a/src/ansys/aedt/core/__init__.py +++ b/src/ansys/aedt/core/__init__.py @@ -29,7 +29,14 @@ if os.name == "nt": os.environ["PYTHONMALLOC"] = "malloc" -LATEST_DEPRECATED_PYTHON_VERSION = (3, 7) +LATEST_DEPRECATED_PYTHON_VERSION = (3, 9) +WARNING_MESSAGE = ( + "As part of our ongoing efforts to align with the Python Scientific Community's " + "best practices, we are moving towards adopting SPEC 0000 " + "(https://scientific-python.org/specs/spec-0000/). To ensure compatibility and " + "take full advantage of the latest features and improvements, we strongly " + "recommend updating the Python version being used." +) def deprecation_warning(): @@ -46,13 +53,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non current_version = sys.version_info[:2] if current_version <= LATEST_DEPRECATED_PYTHON_VERSION: - str_current_version = "{}.{}".format(*sys.version_info[:2]) - warnings.warn( - "Current python version ({}) is deprecated in PyAEDT. We encourage you " - "to upgrade to the latest version to benefit from the latest features " - "and security updates.".format(str_current_version), - PendingDeprecationWarning, - ) + warnings.warn(WARNING_MESSAGE, FutureWarning) # Restore warnings showwarning warnings.showwarning = existing_showwarning