Skip to content

Commit 3557679

Browse files
authored
Feat: Add version to website (#17)
* add version to site * change build backend to hatch * .
1 parent fe5452d commit 3557679

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[tool.hatch.version]
6+
path = "wavey/__init__.py"
7+
18
[project]
29
name = "wavey"
3-
version = "0.1.0"
10+
dynamic = ["version"]
411
authors = [
5-
{name = "Kevin Chen"},
12+
{name = "Kevin Chen", email = "kevinddchen@ucla.edu"},
613
]
714
description = "Visualizing nearshore wave forecasts for Monterey scuba diving"
815
readme = "README.md"

uv.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wavey/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

wavey/__main__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from jinja2 import Environment, PackageLoader, select_autoescape
1313
from tqdm import tqdm
1414

15+
import wavey
1516
from wavey.common import DATETIME_FORMAT, FEET_PER_METER, TZ_PACIFIC, TZ_UTC, setup_logging
1617
from wavey.grib import NUM_DATA_POINTS, ForecastType, read_forecast_data
1718
from wavey.map import DEFAULT_ARROW_LENGTH, RESOLUTION, Map
@@ -85,8 +86,6 @@ def main(
8586
if resolution != "f":
8687
LOG.warning("Not drawing full resolution coastlines. Use the flag '--resolution f'")
8788

88-
out_dir.mkdir(parents=True, exist_ok=True)
89-
9089
# Download data, if needed
9190

9291
if grib_path is None:
@@ -116,9 +115,9 @@ def main(
116115
mon_wave_heights_ft = wave_height_ft[..., MONASTERY_LAT_IDX, MONASTERY_LON_IDX]
117116
assert not np.ma.is_masked(mon_wave_heights_ft), "Unexpected: Monastery data contains masked points"
118117

119-
# Draw Breakwater graph
118+
# Plotting swell graph
120119

121-
LOG.info("Drawing swell graph")
120+
LOG.info("Plotting swell graph")
122121
fig, ax = plt.subplots(figsize=(9, 3), dpi=DPI)
123122

124123
# NOTE: need to erase timezone info for mlpd3 to plot local times correctly
@@ -136,7 +135,7 @@ def main(
136135
plt.tight_layout()
137136
fig_div = mpld3.fig_to_html(fig)
138137

139-
# Draw figure
138+
# Draw maps
140139

141140
fig = plt.figure(figsize=(8, 10), dpi=DPI)
142141
gs = fig.add_gridspec(2, 2, height_ratios=[3, 1])
@@ -195,6 +194,7 @@ def main(
195194
plt.tight_layout()
196195
plt.colorbar(map_main.img, orientation="vertical", label="(ft)", shrink=0.8)
197196

197+
LOG.info("Creating colormap frames")
198198
plot_dir = out_dir / "plots"
199199
plot_dir.mkdir(parents=True, exist_ok=True)
200200
for hour_i in tqdm(range(NUM_DATA_POINTS)):
@@ -208,22 +208,26 @@ def main(
208208
ax_main.set_title(f"Significant wave height (ft) and wave direction\nHour {hour_i:03} -- {pacific_time_str}")
209209
savefig(plot_dir / f"{hour_i}.png")
210210

211-
# Get current time
211+
# Get current time and version
212212

213213
now_utc = datetime.datetime.now(tz=TZ_UTC)
214214
now_pacific = now_utc.astimezone(tz=TZ_PACIFIC)
215215
now_pacific_str = now_pacific.strftime(DATETIME_FORMAT)
216216

217+
version = wavey.__version__
218+
217219
# Export HTML
218220

219-
LOG.info(f"Saving webpage to '{out_dir}'")
221+
out_html_path = out_dir / "index.html"
222+
LOG.info(f"Saving webpage to '{out_html_path}'")
220223
env = Environment(loader=PackageLoader("wavey"), autoescape=select_autoescape())
221224
template_html = env.get_template("index.html.j2")
222225
out_html = template_html.render(
223226
swell_graph=fig_div,
224227
last_updated=now_pacific_str,
228+
version=version,
225229
)
226-
(out_dir / "index.html").write_text(out_html)
230+
out_html_path.write_text(out_html)
227231

228232

229233
if __name__ == "__main__":

wavey/templates/index.html.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
{{ swell_graph }}
5757
</div>
5858

59-
<div><i>Last updated: {{ last_updated }}</i></div>
59+
<div><i>Last updated: {{ last_updated }} [v{{ version }}]</i></div>
6060
<div><a href="https://github.com/kevinddchen/wavey">Github</a></div>
6161

6262
</body>

0 commit comments

Comments
 (0)