diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a33484..4011b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ ### Breaking changes +- Finalized making the following modules private ``_cartopy_utils``, ``_colormaps``, + ``_map_layout``, ``_mpl``, and ``_xrcompat``, started in v0.6.0 ([#234](https://github.com/mpytools/mplotutils/pull/234)). - Removed support for python 3.11 ([#233](https://github.com/mpytools/mplotutils/pull/233)). - ### Enhancements ### Bug fixes diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index 37f547b..7d8f13d 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -14,7 +14,6 @@ ) from mplotutils._colorbar import colorbar from mplotutils._colormaps import from_levels_and_cmap -from mplotutils._deprecate import _module_renamed_warning_init from mplotutils._hatch import hatch, hatch_map, hatch_map_global from mplotutils._map_layout import set_map_layout from mplotutils._mpl import _get_renderer @@ -50,28 +49,3 @@ # Local copy or not installed with setuptools. # Disable minimum version checks on downstream libraries. __version__ = "999" - - -def __getattr__(attr): - - m = ( - "cartopy_utils", - "colormaps", - "map_layout", - "mpl", - ) - - import mplotutils - - if attr in m: - - _module_renamed_warning_init(attr) - - # NOTE: could use importlib.import_module() but it registers the function in - # sys.modules such that the warning is only called once - # return importlib.import_module(f".{attr}", "mplotutils") - - return getattr(mplotutils, f"_{attr}") - - # required for ipython tab completion - raise AttributeError(f"module {__name__!r} has no attribute {attr!r}") diff --git a/mplotutils/_deprecate.py b/mplotutils/_deprecate.py deleted file mode 100644 index 336afd4..0000000 --- a/mplotutils/_deprecate.py +++ /dev/null @@ -1,29 +0,0 @@ -import warnings - - -def _module_renamed_warning_init(attr): - - old_module = f"mplotutils.{attr}" - new_module = f"mplotutils._{attr}" - - msg = ( - f"``{old_module}`` is deprecated and has been renamed to ``{new_module}`` in v0.6.0.." - f" Note that importing ``{new_module}`` is discuraged. Please use" - f" functions directly from the main namespace." - ) - - warnings.warn(msg, FutureWarning, stacklevel=2) - - -def _module_renamed_warning(attr, submodule): - - old_module = f"mplotutils.{submodule}" - new_module = f"mplotutils._{submodule}" - - warnings.warn( - f"``{old_module}`` is deprecated and has been renamed to ``{new_module}`` in v0.6.0." - f" Note that importing from ``{new_module}`` is discuraged. Please use" - f" functions directly from the main namespace, i.e., ``mplotutils.{attr}``", - FutureWarning, - stacklevel=3, - ) diff --git a/mplotutils/cartopy_utils.py b/mplotutils/cartopy_utils.py deleted file mode 100644 index b9344ad..0000000 --- a/mplotutils/cartopy_utils.py +++ /dev/null @@ -1,8 +0,0 @@ -from mplotutils import _cartopy_utils -from mplotutils._deprecate import _module_renamed_warning - - -def __getattr__(attr_name): - attr = getattr(_cartopy_utils, attr_name) - _module_renamed_warning(attr_name, "cartopy_utils") - return attr diff --git a/mplotutils/colormaps.py b/mplotutils/colormaps.py deleted file mode 100644 index 2c5edd8..0000000 --- a/mplotutils/colormaps.py +++ /dev/null @@ -1,8 +0,0 @@ -from mplotutils import _colormaps -from mplotutils._deprecate import _module_renamed_warning - - -def __getattr__(attr_name): - attr = getattr(_colormaps, attr_name) - _module_renamed_warning(attr_name, "colormaps") - return attr diff --git a/mplotutils/map_layout.py b/mplotutils/map_layout.py deleted file mode 100644 index 6c683d1..0000000 --- a/mplotutils/map_layout.py +++ /dev/null @@ -1,8 +0,0 @@ -from mplotutils import _map_layout -from mplotutils._deprecate import _module_renamed_warning - - -def __getattr__(attr_name): - attr = getattr(_map_layout, attr_name) - _module_renamed_warning(attr_name, "map_layout") - return attr diff --git a/mplotutils/mpl.py b/mplotutils/mpl.py deleted file mode 100644 index f6ed3c4..0000000 --- a/mplotutils/mpl.py +++ /dev/null @@ -1,8 +0,0 @@ -from mplotutils import _mpl -from mplotutils._deprecate import _module_renamed_warning - - -def __getattr__(attr_name): - attr = getattr(_mpl, attr_name) - _module_renamed_warning(attr_name, "mpl") - return attr diff --git a/mplotutils/tests/test_rename_modules.py b/mplotutils/tests/test_rename_modules.py deleted file mode 100644 index 37031c2..0000000 --- a/mplotutils/tests/test_rename_modules.py +++ /dev/null @@ -1,61 +0,0 @@ -import importlib - -import pytest - -import mplotutils as mpu - -DEPRECATED_MODULES = { - "cartopy_utils": ( - "cyclic_dataarray", - "sample_data_map", - "sample_dataarray", - "xlabel_map", - "xticklabels", - "ylabel_map", - "yticklabels", - ), - "colormaps": ("from_levels_and_cmap",), - "map_layout": ("set_map_layout",), - "mpl": ("_get_renderer",), -} - - -def test_00_deprecated_not_in_dir(): - - dir = mpu.__dir__() - - for module in DEPRECATED_MODULES: - assert module not in dir - - -def test_01_in_dir(): - - dir = mpu.__dir__() - - assert "hatch" in dir - - -@pytest.mark.parametrize("mod", DEPRECATED_MODULES) -def test_01_deprecated_modules_from_import(mod): - - with pytest.warns(FutureWarning, match=f"``mplotutils.{mod}`` is deprecated"): - importlib.__import__("mplotutils", fromlist=[mod]) - - -@pytest.mark.parametrize("mod, functions", DEPRECATED_MODULES.items()) -def test_depm3(mod, functions): - - module = importlib.import_module(f"mplotutils.{mod}") - - for function in functions: - with pytest.warns(FutureWarning, match=f"``mplotutils.{mod}`` is deprecated"): - getattr(module, function) - - -def test_fcn_warns(): - - # NOTE: this is the only import that does not warn - import mplotutils.cartopy_utils - - with pytest.warns(FutureWarning): - mplotutils.cartopy_utils.sample_data_map(6, 6)