-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
286 lines (245 loc) · 8.18 KB
/
Copy pathstreamlit_app.py
File metadata and controls
286 lines (245 loc) · 8.18 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import re
from dataclasses import replace
from datetime import date
from urllib.parse import urlparse
import streamlit as st
from github_roadmap import (
GitHubAPIError,
MilestoneSection,
RoadmapItem,
ellipsize_title,
load_past_release_items,
load_roadmap,
)
from roadmap_icons import icon_for_issue
GITHUB_REPOSITORY_URL = "https://github.com/streamlit/streamlit"
RELEASE_NOTES_URL = "https://docs.streamlit.io/develop/quick-reference/release-notes"
STREAMLIT_LOGO_URL = "https://streamlit.io/images/brand/streamlit-mark-color.svg"
TTL = 4 * 60 * 60
ROADMAP_CACHE_VERSION = 8
STATUS_COLORS = {
"Targeted": "blue",
"Planned": "orange",
"In review": "violet",
"Complete": "green",
}
st.set_page_config(page_title="Streamlit roadmap", page_icon=STREAMLIT_LOGO_URL)
def _get_github_token() -> str | None:
try:
github_secrets = st.secrets.get("github", {})
except st.errors.StreamlitSecretNotFoundError:
return None
token = github_secrets.get("token")
return str(token) if token else None
@st.cache_data(
ttl=TTL,
max_entries=1,
show_spinner=False,
refresh_mode="background",
)
def _get_roadmap(_github_token: str | None, cache_version: int):
del cache_version
return load_roadmap(_github_token)
@st.cache_data(
ttl=TTL,
max_entries=1,
show_spinner=False,
refresh_mode="background",
)
def _get_past_release_items(
_github_token: str | None,
milestone_numbers: tuple[int, ...],
cache_version: int,
):
del cache_version
return load_past_release_items(milestone_numbers, _github_token)
def _escape_markdown(text: str) -> str:
parts = re.split(r"(`[^`\n]+`)", text)
return "".join(
part if index % 2 else re.sub(r"([\\`*_[\]{}<>#+!|~-])", r"\\\1", part)
for index, part in enumerate(parts)
)
def _format_date(value: date) -> str:
return f"{value:%B} {value.day}, {value.year}"
def _safe_github_url(url: str) -> str:
parsed_url = urlparse(url)
if (
parsed_url.scheme == "https"
and parsed_url.netloc == "github.com"
and parsed_url.path.startswith("/streamlit/streamlit/")
):
return url
return GITHUB_REPOSITORY_URL
def _draw_item(
item: RoadmapItem,
*,
item_kind: str,
status_label: str,
) -> None:
if item.is_closed:
status_label = "Complete"
source = "PR" if item_kind == "pull request" else "Issue"
with st.container(border=True, gap="xsmall"):
with st.container(
horizontal=True,
vertical_alignment="center",
gap="xsmall",
):
title = _escape_markdown(ellipsize_title(item.title))
with st.container(
horizontal=True,
vertical_alignment="center",
gap="xsmall",
width="stretch",
):
if item_kind == "issue":
st.markdown(icon_for_issue(item.labels), width="content")
st.markdown(title, width="stretch")
st.badge(
status_label,
color=STATUS_COLORS[status_label],
width="content",
)
st.link_button(
":material/open_in_new:",
_safe_github_url(item.url),
type="tertiary",
help=f"Open {source.lower()} #{item.number} on GitHub",
width="content",
)
if item.description:
st.caption(item.description)
def _draw_items(
items: tuple[RoadmapItem, ...],
*,
empty_message: str,
status_label: str,
item_kind: str = "issue",
) -> None:
if not items:
st.caption(empty_message)
return
with st.container(gap="xsmall"):
for item in items:
_draw_item(
item,
item_kind=item_kind,
status_label=status_label,
)
def _draw_release(section: MilestoneSection, *, is_past: bool = False) -> None:
st.subheader(section.title)
release_date = _format_date(section.due_on) if section.due_on else "To be announced"
date_label = "Release date" if is_past else "Target release"
st.caption(
f"{date_label}: **{release_date}** · [View milestone on GitHub]({section.url})"
)
st.space("xsmall")
_draw_items(
section.items,
empty_message=(
"No roadmap issues were assigned to this milestone."
if is_past
else "No roadmap issues in this milestone yet."
),
status_label="Complete" if is_past else "Targeted",
)
def _draw_past_releases(
releases: tuple[MilestoneSection, ...],
github_token: str | None,
) -> None:
expander = st.expander(
"Show past releases",
icon=":material/history:",
key="past_releases",
on_change="rerun",
)
with expander:
if not expander.open:
return
st.caption(f"[Read the official release notes]({RELEASE_NOTES_URL})")
if not releases:
st.caption("No past release milestones are currently published.")
return
try:
with st.spinner("Fetching past releases from GitHub…", show_time=True):
items_by_milestone = _get_past_release_items(
github_token,
tuple(release.number for release in releases),
ROADMAP_CACHE_VERSION,
)
except GitHubAPIError as exc:
st.error("We couldn't load past release issues from GitHub.")
st.caption(str(exc))
return
for release in releases:
_draw_release(
replace(
release,
items=items_by_milestone.get(release.number, ()),
),
is_past=True,
)
st.image(STREAMLIT_LOGO_URL, width=78)
st.title("Streamlit roadmap")
st.write(
"See what we're planning for [upcoming Streamlit releases](#upcoming-releases), "
"what else is on our [near-term roadmap](#planned), and which "
"[new feature specs](#specs-in-review) are being reviewed."
)
st.info(
"Need a feature that's not here? "
"[Tell us by opening a GitHub issue.]"
"(https://github.com/streamlit/streamlit/issues)\n\n"
"To help Streamlit prioritize a feature, upvote issues on GitHub with a 👍. "
"Your vote helps us identify which enhancements matter most to our users.",
icon=":material/lightbulb:",
)
roadmap_area = st.container()
github_token = _get_github_token()
try:
with st.spinner("Fetching the latest roadmap from GitHub…", show_time=True):
roadmap = _get_roadmap(github_token, ROADMAP_CACHE_VERSION)
except GitHubAPIError as exc:
roadmap_area.error(
"We couldn't load the roadmap from GitHub. Please try again in a few minutes.",
icon=":material/error:",
)
roadmap_area.caption(str(exc))
st.stop()
with roadmap_area:
_draw_past_releases(roadmap.past_releases, github_token)
st.header("Upcoming releases")
if roadmap.releases:
for release in roadmap.releases:
_draw_release(release)
else:
st.caption("No upcoming release milestones are currently published.")
st.header("Planned")
if roadmap.planned:
st.caption(
"Other projects we think we're likely to ship within the next few months. "
f"· [View milestone on GitHub]({roadmap.planned.url})"
)
st.space("xsmall")
_draw_items(
roadmap.planned.items,
empty_message="No projects are currently in the Planned milestone.",
status_label="Planned",
)
else:
st.caption(
"Other projects we think we're likely to ship within the next few months. "
"The Planned milestone is not currently published."
)
st.header("Specs in review")
st.caption(
"Product specs for new features and enhancements currently in review. "
"Feel free to comment with your thoughts."
)
st.space("xsmall")
_draw_items(
roadmap.specs,
empty_message="No feature specs are currently in review.",
status_label="In review",
item_kind="pull request",
)