-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
124 lines (107 loc) · 3.74 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
import os
import shutil
import urllib.request
import zipfile
from setuptools import find_packages, setup
requires = ["tornado"]
extras_require = {
"dev": [
"black",
"ruff==0.0.275",
# "coverage",
# "pytest >= 4.6",
# "pytest-cov",
# "sphinx",
],
}
version = "0.1.3"
with open("README.md", encoding="utf-8") as fh:
long_description = fh.read()
# Ensure JS dependencies are downloaded
external_dir = "mesa_viz_tornado/templates/external"
# We use a different path for single-file JS because some of them are loaded
# the same way as Mesa JS files
external_dir_single = "mesa_viz_tornado/templates/js/external"
# First, ensure that the external directories exists
os.makedirs(external_dir, exist_ok=True)
os.makedirs(external_dir_single, exist_ok=True)
def ensure_js_dep(dirname, url):
dst_path = os.path.join(external_dir, dirname)
if os.path.isdir(dst_path):
# Do nothing if already downloaded
return
print(f"Downloading the {dirname} dependency from the internet...")
zip_file = dirname + ".zip"
urllib.request.urlretrieve(url, zip_file)
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall()
shutil.move(dirname, dst_path)
# Cleanup
os.remove(zip_file)
print("Done")
def ensure_js_dep_single(url, out_name=None):
# Used for downloading e.g. D3.js single file
if out_name is None:
out_name = url.split("/")[-1]
dst_path = os.path.join(external_dir_single, out_name)
if os.path.isfile(dst_path):
return
print(f"Downloading the {out_name} dependency from the internet...")
urllib.request.urlretrieve(url, out_name)
shutil.move(out_name, dst_path)
# Important: when you update JS dependency version, make sure to also update the
# hardcoded included files and versions in: mesa_viz_tornado/templates/modular_template.html
# Ensure Bootstrap
bootstrap_version = "5.1.3"
ensure_js_dep(
f"bootstrap-{bootstrap_version}-dist",
f"https://github.com/twbs/bootstrap/releases/download/v{bootstrap_version}/bootstrap-{bootstrap_version}-dist.zip",
)
# Ensure Bootstrap Slider
bootstrap_slider_version = "11.0.2"
ensure_js_dep(
f"bootstrap-slider-{bootstrap_slider_version}",
f"https://github.com/seiyria/bootstrap-slider/archive/refs/tags/v{bootstrap_slider_version}.zip",
)
# Important: when updating the D3 version, make sure to update the constant
# D3_JS_FILE in mesa_viz_tornado/ModularVisualization.py.
d3_version = "7.4.3"
ensure_js_dep_single(
f"https://cdnjs.cloudflare.com/ajax/libs/d3/{d3_version}/d3.min.js",
out_name=f"d3-{d3_version}.min.js",
)
# Important: Make sure to update CHART_JS_FILE in
# mesa_viz_tornado/ModularVisualization.py.
chartjs_version = "3.6.1"
ensure_js_dep_single(
f"https://cdn.jsdelivr.net/npm/chart.js@{chartjs_version}/dist/chart.min.js",
out_name=f"chart-{chartjs_version}.min.js",
)
setup(
name="Mesa-Viz-Tornado",
version=version,
description="Tornado-based visualization framework for Mesa",
long_description=long_description,
long_description_content_type="text/markdown",
author="Project Mesa Team",
author_email="projectmesa@googlegroups.com",
url="https://github.com/projectmesa/mesa-viz-tornado",
packages=find_packages(),
package_data={
"mesa_viz_tornado": [
"templates/*.html",
"templates/css/*",
"templates/js/*",
"templates/js/external/*",
"templates/external/**/*",
],
},
include_package_data=True,
install_requires=requires,
extras_require=extras_require,
keywords="agent based modeling model ABM simulation multi-agent",
license="Apache 2.0",
zip_safe=False,
python_requires=">=3.8",
)