forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_examples.py
More file actions
executable file
·107 lines (86 loc) · 3.11 KB
/
run_all_examples.py
File metadata and controls
executable file
·107 lines (86 loc) · 3.11 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
#!/usr/bin/env python
# Copyright 2018-2021 Streamlit Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Runs all the scripts in the examples folder (except this one)."""
import os
import sys
import click
# True means we run through all tests automatically.
auto_run = False
# Where we expect to find the example files.
EXAMPLE_DIR = "examples"
# These are all the files we excliude
EXCLUDED_FILENAMES = (
# Exclude mnist becuase it takes so long to run.
"mnist-cnn.py",
# Exclude caching because we special case it.
"caching.py",
)
def run_commands(section_header, commands, skip_last_input=False, comment=None):
"""Run a list of commands, displaying them within the given section."""
global auto_run
for i, command in enumerate(commands):
# Display the status.
vars = {
"section_header": section_header,
"total": len(commands),
"command": command,
"v": i + 1,
}
click.secho(
"\nRunning %(section_header)s %(v)s/%(total)s : %(command)s" % vars,
bold=True,
)
click.secho("\n%(v)s/%(total)s : %(command)s" % vars, fg="yellow", bold=True)
if comment:
click.secho(comment)
# Run the command.
os.system(command)
last_command = i + 1 == len(commands)
if not (auto_run or (last_command and skip_last_input)):
click.secho(
"Press [enter] to continue or [a] to continue on auto:\n> ", nl=False
)
response = click.getchar()
if response == "a":
print("Turning on auto run.")
auto_run = True
def main():
# First run the 'streamlit commands'
run_commands("Basic Commands", ["streamlit version"])
run_commands(
"Standard System Errors",
["streamlit run does_not_exist.py"],
comment="Checks to see that file not found error is caught",
)
run_commands("Hello script", ["streamlit hello"])
run_commands(
"Examples",
[
"streamlit run %(EXAMPLE_DIR)s/%(filename)s"
% {"EXAMPLE_DIR": EXAMPLE_DIR, "filename": filename}
for filename in os.listdir(EXAMPLE_DIR)
if filename.endswith(".py") and filename not in EXCLUDED_FILENAMES
],
)
run_commands(
"Caching",
["streamlit cache clear", "streamlit run %s/caching.py" % EXAMPLE_DIR],
)
run_commands(
"MNIST", ["streamlit run %s/mnist-cnn.py" % EXAMPLE_DIR], skip_last_input=True
)
click.secho("\n\nCompleted all tests!", bold=True)
if __name__ == "__main__":
main()