Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Wikipedia tile and CI maintenance #630

Merged
merged 13 commits into from
May 10, 2023
1 change: 1 addition & 0 deletions geoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from .util import load_tiff, from_xarray # noqa (API import)
from .operation import project # noqa (API import)
from ._warnings import GeoviewsDeprecationWarning, GeoviewsUserWarning # noqa: F401
from . import data # noqa (API import)
from . import operation # noqa (API import)
from . import plotting # noqa (API import)
Expand Down
96 changes: 96 additions & 0 deletions geoviews/_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import inspect
import os
import warnings

import holoviews as hv
import param

from packaging.version import Version

__all__ = (
"deprecated",
"find_stack_level",
"GeoviewsDeprecationWarning",
"GeoviewsUserWarning",
"warn",
)


def warn(message, category=None, stacklevel=None):
if stacklevel is None:
stacklevel = find_stack_level()

warnings.warn(message, category, stacklevel=stacklevel)


def find_stack_level():
"""
Find the first place in the stack that is not inside
Geoviews, Holoviews, or Param.

Inspired by: pandas.util._exceptions.find_stack_level
"""
import geoviews as gv

pkg_dir = os.path.dirname(gv.__file__)
test_dir = os.path.join(pkg_dir, "tests")
param_dir = os.path.dirname(param.__file__)
hv_dir = os.path.dirname(hv.__file__)

frame = inspect.currentframe()
stacklevel = 0
while frame:
fname = inspect.getfile(frame)
if (
fname.startswith(pkg_dir)
or fname.startswith(param_dir)
or fname.startswith(hv_dir)
) and not fname.startswith(test_dir):
frame = frame.f_back
stacklevel += 1
else:
break

return stacklevel


def deprecated(remove_version, old, new=None, extra=None):
import geoviews as gv

current_version = Version(Version(gv.__version__).base_version)

if isinstance(remove_version, str):
remove_version = Version(remove_version)

if remove_version < current_version:
# This error is mainly for developers to remove the deprecated.
raise ValueError(
f"{old!r} should have been removed in {remove_version}"
f", current version {current_version}."
)

message = f"{old!r} is deprecated and will be removed in version {remove_version}."

if new:
message = f"{message[:-1]}, use {new!r} instead."

if extra:
message += " " + extra.strip()

warn(message, GeoviewsDeprecationWarning)


class GeoviewsDeprecationWarning(DeprecationWarning):
"""A Geoviews-specific ``DeprecationWarning`` subclass.
Used to selectively filter Geoviews deprecations for unconditional display.
"""


class GeoviewsUserWarning(UserWarning):
"""A Geoviews-specific ``UserWarning`` subclass.
Used to selectively filter Geoviews warnings for unconditional display.
"""


warnings.simplefilter("always", GeoviewsDeprecationWarning)
warnings.simplefilter("always", GeoviewsUserWarning)
4 changes: 2 additions & 2 deletions geoviews/operation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
geo_ops = [contours, bivariate_kde]
try:
from holoviews.operation.datashader import (
ResamplingOperation, shade, stack, dynspread)
geo_ops += [ResamplingOperation, shade, stack, dynspread]
ResamplingOperation2D, shade, stack, dynspread)
geo_ops += [ResamplingOperation2D, shade, stack, dynspread]
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
except:
pass

Expand Down
8 changes: 7 additions & 1 deletion geoviews/tile_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@
# Miscellaneous
OSM = WMTS('https://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="OSM")
OpenTopoMap = WMTS('https://a.tile.opentopomap.org/{Z}/{X}/{Y}.png', name="OpenTopoMap")
Wikipedia = WMTS('https://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="Wikipedia")

def __getattr__(name):
if name == "Wikipedia":
from ._warnings import deprecated
deprecated("1.11", "Wikipedia", "OSM")
return WMTS('https://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="Wikipedia")
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


tile_sources = {k: v for k, v in locals().items() if isinstance(v, WMTS) and k != 'ESRI'}
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ filterwarnings =
ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:cupy
; 2023-01: https://github.com/SciTools/cartopy/issues/2113
ignore:The 'geom_factory' function is deprecated in Shapely 2:DeprecationWarning:cartopy.crs
error::holoviews.HoloviewsDeprecationWarning
error::holoviews.HoloviewsUserWarning
error::geoviews.GeoviewsDeprecationWarning
error::geoviews.GeoviewsUserWarning

[flake8]
include = *.py
Expand Down