Skip to content

Commit c77912a

Browse files
authored
Merge pull request #1675 from plotly/new-docs-extras
New docs extras
2 parents efc42b4 + fcf9ac4 commit c77912a

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55
## [UNRELEASED]
66

77
## Dash and Dash Renderer
8+
### Added
9+
- [#1675](https://github.com/plotly/dash/pull/1675) Add new `Dash` constructor argument `extra_hot_reload_paths`. This allows you to re-initialize the Python code of the app when non-Python files change, if you know that these files impact the app.
10+
811
### Changed
12+
- [#1675](https://github.com/plotly/dash/pull/1675) Remove the constraint that `requests_pathname_prefix` ends with `routes_pathname_prefix`. When you are serving your app behind a reverse proxy that rewrites URLs that constraint needs to be violated.
913
- [#1611](https://github.com/plotly/dash/pull/1611) Package dash-renderer artifacts and dependencies with Dash, and source renderer resources from within Dash.
1014
- [#1567](https://github.com/plotly/dash/pull/1567) Julia component generator puts components into `src/jl` - fixes an issue on case-insensitive filesystems when the component name and module name match (modulo case) and no prefix is used. Also reduces JS/Julia clutter in the overloaded `src` directory.
1115

dash/_configs.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,5 @@ def pathname_configs(
117117
raise exceptions.InvalidConfig(
118118
"`requests_pathname_prefix` needs to start with `/`"
119119
)
120-
if not requests_pathname_prefix.endswith(routes_pathname_prefix):
121-
raise exceptions.InvalidConfig(
122-
"`requests_pathname_prefix` needs to ends with `routes_pathname_prefix`."
123-
)
124120

125121
return url_base_pathname, routes_pathname_prefix, requests_pathname_prefix

dash/dash.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ class Dash(object):
232232
and redo buttons for stepping through the history of the app state.
233233
:type show_undo_redo: boolean
234234
235+
:param extra_hot_reload_paths: A list of paths to watch for changes, in
236+
addition to assets and known Python and JS code, if hot reloading is
237+
enabled.
238+
:type extra_hot_reload_paths: list of strings
239+
235240
:param plugins: Extend Dash functionality by passing a list of objects
236241
with a ``plug`` method, taking a single argument: this app, which will
237242
be called after the Flask server is attached.
@@ -269,6 +274,7 @@ def __init__(
269274
suppress_callback_exceptions=None,
270275
prevent_initial_callbacks=False,
271276
show_undo_redo=False,
277+
extra_hot_reload_paths=None,
272278
plugins=None,
273279
title="Dash",
274280
update_title="Updating...",
@@ -329,6 +335,7 @@ def __init__(
329335
),
330336
prevent_initial_callbacks=prevent_initial_callbacks,
331337
show_undo_redo=show_undo_redo,
338+
extra_hot_reload_paths=extra_hot_reload_paths or [],
332339
title=title,
333340
update_title=update_title,
334341
)
@@ -1730,4 +1737,14 @@ def verify_url_part(served_part, url_part, part_name):
17301737

17311738
self.logger.info("Dash is running on %s://%s%s%s\n", *display_url)
17321739

1740+
if self.config.extra_hot_reload_paths:
1741+
extra_files = flask_run_options["extra_files"] = []
1742+
for path in self.config.extra_hot_reload_paths:
1743+
if os.path.isdir(path):
1744+
for dirpath, _, filenames in os.walk(path):
1745+
for fn in filenames:
1746+
extra_files.append(os.path.join(dirpath, fn))
1747+
elif os.path.isfile(path):
1748+
extra_files.append(path)
1749+
17331750
self.server.run(host=host, port=port, debug=debug, **flask_run_options)

dash/development/component_generator.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def generate_components(
4949
rimports="",
5050
rsuggests="",
5151
jlprefix=None,
52+
metadata=None,
5253
):
5354

5455
project_shortname = project_shortname.replace("-", "_").rstrip("/\\")
@@ -61,36 +62,37 @@ def generate_components(
6162

6263
os.environ["NODE_PATH"] = "node_modules"
6364

64-
cmd = shlex.split(
65-
'node {} "{}" "{}" {}'.format(
66-
extract_path, ignore, reserved_patterns, components_source
67-
),
68-
posix=not is_windows,
69-
)
70-
7165
shutil.copyfile(
7266
"package.json", os.path.join(project_shortname, package_info_filename)
7367
)
7468

75-
proc = subprocess.Popen(
76-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=is_windows
77-
)
78-
out, err = proc.communicate()
79-
status = proc.poll()
80-
81-
if err:
82-
print(err.decode(), file=sys.stderr)
83-
84-
if not out:
85-
print(
86-
"Error generating metadata in {} (status={})".format(
87-
project_shortname, status
69+
if not metadata:
70+
cmd = shlex.split(
71+
'node {} "{}" "{}" {}'.format(
72+
extract_path, ignore, reserved_patterns, components_source
8873
),
89-
file=sys.stderr,
74+
posix=not is_windows,
75+
)
76+
77+
proc = subprocess.Popen(
78+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=is_windows
9079
)
91-
sys.exit(1)
80+
out, err = proc.communicate()
81+
status = proc.poll()
82+
83+
if err:
84+
print(err.decode(), file=sys.stderr)
85+
86+
if not out:
87+
print(
88+
"Error generating metadata in {} (status={})".format(
89+
project_shortname, status
90+
),
91+
file=sys.stderr,
92+
)
93+
sys.exit(1)
9294

93-
metadata = safe_json_loads(out.decode("utf-8"))
95+
metadata = safe_json_loads(out.decode("utf-8"))
9496

9597
generator_methods = [generate_class_file]
9698

@@ -148,7 +150,7 @@ def safe_json_loads(s):
148150
return byteify(jsondata_unicode)
149151

150152

151-
def cli():
153+
def component_build_arg_parser():
152154
parser = argparse.ArgumentParser(
153155
prog="dash-generate-components",
154156
formatter_class=_CombinedFormatter,
@@ -199,8 +201,11 @@ def cli():
199201
help="Specify a prefix for Dash for R component names, write "
200202
"components to R dir, create R package.",
201203
)
204+
return parser
205+
202206

203-
args = parser.parse_args()
207+
def cli():
208+
args = component_build_arg_parser().parse_args()
204209
generate_components(
205210
args.components_source,
206211
args.project_shortname,

0 commit comments

Comments
 (0)