From 6706689817577d77a0349503dd7ecb7338bf3df5 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Mon, 15 May 2023 09:31:36 +0100 Subject: [PATCH 1/2] Fix imports of marker_trait Add it back to chaco.api but with a deprecation warning. --- chaco/api.py | 16 ++++++++++++++- chaco/tests/test_api.py | 24 ++++++++++++++++++++++ docs/source/user_manual/chaco_tutorial.rst | 4 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 chaco/tests/test_api.py diff --git a/chaco/api.py b/chaco/api.py index 61492745f..9653ecf98 100644 --- a/chaco/api.py +++ b/chaco/api.py @@ -498,7 +498,7 @@ YlGn, YlGnBu, YlOrBr, - YlOrRd, + YlOrRd, gist_earth, gist_gray, gist_heat, @@ -527,3 +527,17 @@ Set3, ) from .default_colors import cbrewer, palette11, palette14, PALETTES + + +def __getattr__(name): + """Backward compatibility lazy imports. + + These imports warn about backwards incompatible changes. + """ + if name in {'marker_trait'}: + from warnings import warn + import enable.api + warn(f"Please import {name} from enable.api instead of chaco.api.") + return getattr(enable.api, name) + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/chaco/tests/test_api.py b/chaco/tests/test_api.py new file mode 100644 index 000000000..ccc83ff68 --- /dev/null +++ b/chaco/tests/test_api.py @@ -0,0 +1,24 @@ +# (C) Copyright 2005-2021 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 + +import chaco.api + + +class TestAPI(unittest.TestCase): + + def test_enable_imports(self): + """Test for deprecated imports from enable.api""" + names = {'marker_trait'} + for name in names: + with self.subTest(name=name): + with self.assertWarns(DeprecationWarning): + getattr(chaco.api, name) diff --git a/docs/source/user_manual/chaco_tutorial.rst b/docs/source/user_manual/chaco_tutorial.rst index 14faf82c7..27c333f2a 100644 --- a/docs/source/user_manual/chaco_tutorial.rst +++ b/docs/source/user_manual/chaco_tutorial.rst @@ -559,8 +559,8 @@ of these capabilities. Here is the full listing of the modified code:: from numpy import linspace, sin from traits.api import HasTraits, Instance, Int from traitsui.api import Item, Group, View - from chaco.api import ArrayPlotData, marker_trait, Plot - from enable.api import ColorTrait, ComponentEditor + from chaco.api import ArrayPlotData, Plot + from enable.api import ColorTrait, ComponentEditor, marker_trait class ScatterPlotTraits(HasTraits): From 4c0644f22942897163ba514e2d3f4fe2329e587f Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Mon, 15 May 2023 10:16:07 +0100 Subject: [PATCH 2/2] Make warning a DeprecationWarning --- chaco/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chaco/api.py b/chaco/api.py index 9653ecf98..d9e0c4ee6 100644 --- a/chaco/api.py +++ b/chaco/api.py @@ -537,7 +537,10 @@ def __getattr__(name): if name in {'marker_trait'}: from warnings import warn import enable.api - warn(f"Please import {name} from enable.api instead of chaco.api.") + warn( + f"Please import {name} from enable.api instead of chaco.api.", + DeprecationWarning, + ) return getattr(enable.api, name) raise AttributeError(f"module {__name__!r} has no attribute {name!r}")