Skip to content

Commit 7345d87

Browse files
wang-boyurht
authored andcommitted
remove version number from leaflet filenames
1 parent 048d0dd commit 7345d87

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

mesa_geo/visualization/modules/MapVisualization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class MapModule(VisualizationElement):
66
"""A MapModule for Leaflet maps."""
77

8-
package_includes = ["external/leaflet-1.8.0.js", "MapModule.js"]
8+
package_includes = ["external/leaflet.js", "MapModule.js"]
99
local_includes = []
1010

1111
def __init__(

mesa_geo/visualization/templates/modular_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link href="/static/css/bootstrap-switch.min.css" type="text/css" rel="stylesheet" />
77
<link href="/static/css/bootstrap-slider.min.css" type="text/css" rel="stylesheet" />
88
<link href="/static/css/visualization.css" type="text/css" rel="stylesheet" />
9-
<link href="/static/css/external/leaflet-1.8.0.css" type="text/css" rel="stylesheet" />
9+
<link href="/static/css/external/leaflet.css" type="text/css" rel="stylesheet" />
1010

1111
<!-- This is the Tornado template for the Modular Visualization. The Javascript code opens a WebSocket connection to
1212
the server (the port is set via the template). On every step, it receives inputs, one per module, and sends

setup.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ def get_mesa_templates(package, template_dir):
6666

6767

6868
def get_frontend_dep():
69-
# Important: Make sure to update package_includes with the new version number in
70-
# mesa_geo/visualization/modules/MapVisualization.py,
71-
# and the hardcoded css file in mesa_geo/visualization/templates/modular_template.html.
69+
# Important: Make sure to update the integrity_hash together with the new version number,
70+
# otherwise the previous file is going to be kept and used.
7271
leaflet_version = "1.8.0"
7372
ensure_frontend_dep_single(
7473
f"https://unpkg.com/leaflet@{leaflet_version}/dist/leaflet.js",
75-
out_name=f"leaflet-{leaflet_version}.js",
7674
external_dir_single="mesa_geo/visualization/templates/js/external",
7775
integrity_hash="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==",
7876
)
7977
ensure_frontend_dep_single(
8078
f"https://unpkg.com/leaflet@{leaflet_version}/dist/leaflet.css",
81-
out_name=f"leaflet-{leaflet_version}.css",
8279
external_dir_single="mesa_geo/visualization/templates/css/external",
8380
integrity_hash="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==",
8481
)
@@ -87,24 +84,29 @@ def get_frontend_dep():
8784
def ensure_frontend_dep_single(
8885
url, external_dir_single, out_name=None, integrity_hash=None
8986
):
87+
def _hash(filepath):
88+
with open(filepath, "rb") as f:
89+
file_as_bytes = f.read()
90+
file_hash = base64.b64encode(hashlib.sha512(file_as_bytes).digest())
91+
return "sha512-" + file_hash.decode()
92+
9093
os.makedirs(external_dir_single, exist_ok=True)
9194
# Used for downloading e.g. Leaflet single file
9295
if out_name is None:
9396
out_name = url.split("/")[-1]
9497
dst_path = os.path.join(external_dir_single, out_name)
9598
if os.path.isfile(dst_path):
96-
return
99+
if integrity_hash and (_hash(dst_path) == integrity_hash):
100+
return
101+
else:
102+
return
103+
print(f"Downloading the {out_name} dependency from the internet...")
97104
urllib.request.urlretrieve(url, out_name)
98-
if integrity_hash:
99-
with open(out_name, "rb") as f:
100-
bytes = f.read()
101-
actual_hash = base64.b64encode(hashlib.sha512(bytes).digest())
102-
actual_hash = "sha512-" + actual_hash.decode()
103-
if actual_hash != integrity_hash:
104-
os.remove(out_name)
105-
raise ValueError(
106-
f"Integrity check failed for {out_name}. Expected {integrity_hash}, received {actual_hash}."
107-
)
105+
if integrity_hash and ((actual_hash := _hash(out_name)) != integrity_hash):
106+
os.remove(out_name)
107+
raise ValueError(
108+
f"Integrity check failed for {out_name}. Expected {integrity_hash}, received {actual_hash}."
109+
)
108110
shutil.move(out_name, dst_path)
109111

110112

0 commit comments

Comments
 (0)