From 622ad6e7c75ffd0ff9892fd5e198c52d2a97a9de Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Mon, 13 Jul 2026 13:56:50 +0200 Subject: [PATCH 1/4] finalize make modules private --- mplotutils/__init__.py | 23 ---------- mplotutils/_deprecate.py | 29 ------------ mplotutils/cartopy_utils.py | 8 ---- mplotutils/colormaps.py | 8 ---- mplotutils/map_layout.py | 8 ---- mplotutils/mpl.py | 8 ---- mplotutils/tests/test_rename_modules.py | 61 ------------------------- 7 files changed, 145 deletions(-) delete mode 100644 mplotutils/_deprecate.py delete mode 100644 mplotutils/cartopy_utils.py delete mode 100644 mplotutils/colormaps.py delete mode 100644 mplotutils/map_layout.py delete mode 100644 mplotutils/mpl.py delete mode 100644 mplotutils/tests/test_rename_modules.py diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index 37f547b..68021ef 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -52,26 +52,3 @@ __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) From d085c55587030ff619f6da0b59ad3a494f05969b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jul 2026 11:58:12 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mplotutils/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index 68021ef..1870b77 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -50,5 +50,3 @@ # Local copy or not installed with setuptools. # Disable minimum version checks on downstream libraries. __version__ = "999" - - From b0b76846af4e9fcb7ec63233eb8df4ce62128ff3 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Mon, 13 Jul 2026 14:01:31 +0200 Subject: [PATCH 3/4] remove import --- mplotutils/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index 68021ef..b1b20f3 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 From f523e996e9d7922ce6a5c6e5997b33d421d3c2d2 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Mon, 13 Jul 2026 14:01:39 +0200 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c37ad..35d5b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### 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)). + ### Enhancements ### Bug fixes