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

Remove _env instance attributes #1817

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, List, Optional, Sequence, Union

from branca.element import Element, Figure, MacroElement
from jinja2 import Environment, PackageLoader, Template
from jinja2 import Template

from folium.elements import JSCSSMixin
from folium.map import FitBounds, Layer
Expand All @@ -22,8 +22,6 @@
validate_location,
)

ENV = Environment(loader=PackageLoader("folium", "templates"))


_default_js = [
("leaflet", "https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"),
Expand Down Expand Up @@ -262,7 +260,6 @@ def __init__(
):
super().__init__()
self._name = "Map"
self._env = ENV

self._png_image: Optional[bytes] = None
self.png_enabled = png_enabled
Expand Down
7 changes: 3 additions & 4 deletions folium/raster_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def __init__(
name=self.tile_name, overlay=overlay, control=control, show=show
)
self._name = "TileLayer"
self._env = ENV

tiles_flat = "".join(tiles.lower().strip().split())
if tiles_flat in {"cloudmade", "mapbox", "mapboxbright", "mapboxcontrolroom"}:
Expand All @@ -133,14 +132,14 @@ def __init__(
"argument. See the documentation of the `TileLayer` class."
)
templates = list(
self._env.list_templates(filter_func=lambda x: x.startswith("tiles/"))
ENV.list_templates(filter_func=lambda x: x.startswith("tiles/"))
)
tile_template = "tiles/" + tiles_flat + "/tiles.txt"
attr_template = "tiles/" + tiles_flat + "/attr.txt"

if tile_template in templates and attr_template in templates:
self.tiles = self._env.get_template(tile_template).render()
attr = self._env.get_template(attr_template).render()
self.tiles = ENV.get_template(tile_template).render()
attr = ENV.get_template(attr_template).render()
else:
self.tiles = tiles
if not attr:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import folium
from folium import TileLayer
from folium.features import Choropleth, GeoJson
from folium.raster_layers import ENV

rootpath = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -120,8 +121,8 @@ def test_builtin_tile(self):
tiles = "".join(tiles.lower().strip().split())
url = "tiles/{}/tiles.txt".format
attr = "tiles/{}/attr.txt".format
url = m._env.get_template(url(tiles)).render()
attr = m._env.get_template(attr(tiles)).render()
url = ENV.get_template(url(tiles)).render()
attr = ENV.get_template(attr(tiles)).render()

assert m._children[tiles].tiles == url
assert htmlsafe_json_dumps(attr) in m._parent.render()
Expand Down