forked from radovankavicky/dash-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
65 lines (54 loc) · 1.92 KB
/
Copy pathtools.py
File metadata and controls
65 lines (54 loc) · 1.92 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
from server import app
def load_example(path):
with open(path, 'r') as _f:
_source = _f.read()
_example = _source
# Use the global app assignment
if 'app = dash.Dash' not in _example:
raise Exception("Didn't declare app")
_example = _example.replace('app = dash.Dash', '# app = dash.Dash')
commented_configs = [
'app.scripts.config.serve_locally',
'app.css.config.serve_locally'
]
for config in commented_configs:
_example = _example.replace(
config,
'# {}'.format(config)
)
if 'import dash\n' not in _example:
raise Exception("Didn't import dash")
# return the layout instead of assigning it to the global app
if 'app.layout = ' not in _example:
raise Exception('app.layout not assigned')
_example = _example.replace('app.layout = ', 'layout = ')
# Remove the "# Run the server" commands
if 'app.run_server' not in _example:
raise Exception('app.run_server missing')
_example = _example.replace(
'\n app.run_server',
'print("Running")\n # app.run_server'
)
scope = {'app': app}
try:
exec(_example, scope)
except Exception as e:
print('\nError running {}\n{}'.format(
path,
('======================================' +
'======================================')
))
raise e
return (
_source,
scope['layout'] # layout is a global created from the app
)
def merge(*dict_args):
"""
Given any number of dicts, shallow copy and merge into a new dict,
precedence goes to key value pairs in latter dicts.
"""
result = {}
for dictionary in dict_args:
result.update(dictionary)
return result