From 60f918ede682bc2bb096e4c60196cf0b4404d1d3 Mon Sep 17 00:00:00 2001 From: homosapien-lcy <102019577+homosapien-lcy@users.noreply.github.com> Date: Fri, 21 Apr 2023 18:45:20 +0900 Subject: [PATCH] MAINT: replace deprecated version check for traitsui (#1746) In traitsui, traitsui.__version__ has been deprecated and should be replaced with importlib.metadata.version('traitsui'). The deprecation warning raised have also caused test_edit_not_given in traits/traits/tests/test_configure_traits.py to fail as mentioned in #1745 . Since the version check is a temporary check to address the dependency of traits on traits ui and is no longer need, the current PR fixed this issue by removing all version checks related to _traitsui_helpers.py. Closes #1745 Co-authored-by: Chengyu Liu --- traits/has_traits.py | 5 --- traits/util/_traitsui_helpers.py | 40 --------------------- traits/util/tests/test_traitsui_helpers.py | 41 ---------------------- 3 files changed, 86 deletions(-) delete mode 100644 traits/util/_traitsui_helpers.py delete mode 100644 traits/util/tests/test_traitsui_helpers.py diff --git a/traits/has_traits.py b/traits/has_traits.py index 56bef1793..606c646d0 100644 --- a/traits/has_traits.py +++ b/traits/has_traits.py @@ -55,7 +55,6 @@ ) from .trait_errors import TraitError from .util.deprecated import deprecated -from .util._traitsui_helpers import check_traitsui_major_version from .trait_converters import check_trait, mapped_trait_for, trait_for @@ -1846,10 +1845,6 @@ def _trait_view( if view_elements is None: return None - # Provide a nicer failure mode when upgrading to Traits using - # TraitsUI 6.x - check_traitsui_major_version(7) - if name: if view_element is None: # If only a name was specified, return the ViewElement it diff --git a/traits/util/_traitsui_helpers.py b/traits/util/_traitsui_helpers.py deleted file mode 100644 index 41d5642aa..000000000 --- a/traits/util/_traitsui_helpers.py +++ /dev/null @@ -1,40 +0,0 @@ -# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -""" Functions to help removing TraitsUI being a dependency of Traits. - -Used internally by traits only. -""" -# All imports of TraitsUI should be delayed. - - -def check_traitsui_major_version(major): - """ Raise RuntimeError if TraitsUI major version is less than the required - value. - - Used internally in traits only. - - Parameters - ---------- - major : int - Required TraitsUI major version. - - Raises - ------ - RuntimeError - """ - from traitsui import __version__ as traitsui_version - actual_major, _ = traitsui_version.split(".", 1) - actual_major = int(actual_major) - if actual_major < major: - raise RuntimeError( - "TraitsUI {} or higher is required. Got version {!r}".format( - major, traitsui_version) - ) diff --git a/traits/util/tests/test_traitsui_helpers.py b/traits/util/tests/test_traitsui_helpers.py deleted file mode 100644 index c32acf4f6..000000000 --- a/traits/util/tests/test_traitsui_helpers.py +++ /dev/null @@ -1,41 +0,0 @@ -# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - - -import unittest -from unittest import mock - -from traits.testing.optional_dependencies import requires_traitsui -from traits.util._traitsui_helpers import check_traitsui_major_version - - -@requires_traitsui -class TestTraitsUIHelper(unittest.TestCase): - - def test_check_version_error(self): - - with mock.patch("traitsui.__version__", "6.1.2"): - with self.assertRaises(RuntimeError) as exception_context: - check_traitsui_major_version(7) - - self.assertEqual( - str(exception_context.exception), - "TraitsUI 7 or higher is required. Got version '6.1.2'" - ) - - def test_check_version_okay(self): - with mock.patch("traitsui.__version__", "7.0.0"): - try: - check_traitsui_major_version(7) - except Exception: - self.fail( - "Given TraitsUI version is okay, " - "sanity check unexpectedly failed." - )