Skip to content

Commit

Permalink
CHORE: Add warning on python version (#5050)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Samuel Lopez <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2024
1 parent b0a0ed3 commit ff1b911
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
28 changes: 16 additions & 12 deletions _unittest/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 9 additions & 8 deletions src/ansys/aedt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down

0 comments on commit ff1b911

Please sign in to comment.