Skip to content

Commit 3c70b4d

Browse files
committed
Refactor deployment script
1 parent ed65042 commit 3c70b4d

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ jobs:
2424
- name: Build the Shinylive site
2525
run: |
2626
# shinylive export getting-started dist
27-
shinylive export --subdir getting-started --template-dir templates/app --template-params '{"title": "MapLibre for Python Getting Started"}' getting-started dist
28-
python ./scripts/rendersite.py > dist/index.html
27+
# shinylive export --subdir getting-started --template-dir templates/app --template-params '{"title": "MapLibre for Python Getting Started"}' getting-started dist
28+
python ./scripts/deploy.py export
29+
python ./scripts/deploy.py render > dist/index.html
2930
- name: Upload artifact
3031
uses: actions/upload-pages-artifact@v3
3132
with:

config/site.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[site]
22
title = "MapLibre for Python"
3+
subtitle = "Shinylive"
34
apps = [{ title = "Getting Started", dir = "getting-started" }]

getting-started/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from shiny import reactive
2-
from shiny.express import input, render, ui
3-
41
from maplibre import Layer, LayerType, Map, MapLibreRenderer, MapOptions
52
from maplibre.basemaps import OpenFreeMap
63
from maplibre.controls import GlobeControl, NavigationControl
74
from maplibre.sources import GeoJSONSource
5+
from shiny import reactive
6+
from shiny.express import input, render, ui
87

98
data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
109
layer_id = "earthquakes"
1110

12-
earthquakes = Layer(id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)).set_paint_props(
13-
circle_color="yellow"
14-
)
11+
earthquakes = Layer(
12+
id=layer_id, type=LayerType.CIRCLE, source=GeoJSONSource(data=data)
13+
).set_paint_props(circle_color="yellow")
1514

1615

1716
@MapLibreRenderer
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
import sys
3+
import json
4+
import subprocess
45
import tomllib
56

67
import typer
@@ -17,7 +18,8 @@ class App(BaseModel):
1718

1819
class Site(BaseModel):
1920
title: str = "MapLibre for Python"
20-
apps: list[App] = [App(title="Getting started", dir="getting-started")]
21+
subtitle: str = "Shinylive"
22+
apps: list[App] # = [App(title="Getting started", dir="getting-started")]
2123

2224
@classmethod
2325
def read_config(cls, filename: str) -> Site:
@@ -41,5 +43,28 @@ def render(
4143
print(site.render(input))
4244

4345

46+
@app.command(help="Export apps")
47+
def export(config: str = "config/site.toml") -> None:
48+
site = Site.read_config(config)
49+
print(site)
50+
for app in site.apps:
51+
cmd = [
52+
"shinylive",
53+
"export",
54+
"--subdir",
55+
app.dir,
56+
"--template-dir",
57+
"templates/app",
58+
"--template-params",
59+
json.dumps(dict(title=app.title)),
60+
app.dir,
61+
"dist",
62+
]
63+
# print(cmd)
64+
result = subprocess.run(cmd, capture_output=True, text=True)
65+
print(result.args)
66+
print(result.stderr)
67+
68+
4469
if __name__ == "__main__":
4570
app()

0 commit comments

Comments
 (0)