Skip to content

Commit

Permalink
Remove _env instance attributes (#1817)
Browse files Browse the repository at this point in the history
* Remove _env instance attributes

* remove ENV from folium.folium

* remove unused imports

* fix pre-commit complaint
  • Loading branch information
Conengmo authored Oct 16, 2023
1 parent 9ab63f7 commit 7268a13
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 1 addition & 5 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,9 +22,6 @@
validate_location,
)

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


_default_js = [
("leaflet", "https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.js"),
("jquery", "https://code.jquery.com/jquery-1.12.4.min.js"),
Expand Down Expand Up @@ -262,7 +259,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

0 comments on commit 7268a13

Please sign in to comment.