Skip to content

Commit 2ec0238

Browse files
authored
Merge pull request #1751 from plotly/dev-aliases
`app.run` instead of `run_server`
2 parents a392f73 + c6d630a commit 2ec0238

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2626

2727
- [#2016](https://github.com/plotly/dash/pull/2016) Drop the 375px width from default percy_snapshot calls, keep only 1280px
2828

29+
- [#1751](https://github.com/plotly/dash/pull/1751) Rename `app.run_server` to `app.run` while preserving `app.run_server` for backwards compatibility.
30+
31+
2932
### Updated
3033
- [#2016](https://github.com/plotly/dash/pull/2016) Widespread dependency upgrades
3134
- Upgrade Plotly.js to v2.11.1 (from v2.11.0). Patch release [2.11.1](https://github.com/plotly/plotly.js/releases/tag/v2.11.1) fixes regl-based traces in strict CSP mode, however you must manually switch to the strict bundle to use this.

MAKE_A_NEW_BACK_END.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Any new back end needs to provide all of that functionality, one way or another.
8080

8181
The `Dash()` constructor has lots of options. They’re all listed and documented [here]( https://github.com/plotly/dash/blob/357f22167d40ef00c92ff165aa6df23c622799f6/dash/dash.py#L113-L253) - some are Python-specific (`name`, `server`, `plugins`), others should eventually be replicated but many can be left out of the first proof-of-concept implementation.
8282

83-
Similarly the `app.run_server` method has a lot of options, listed [here](https://github.com/plotly/dash/blob/357f22167d40ef00c92ff165aa6df23c622799f6/dash/dash.py#L1596-L1671) - again some are Python-specific (`flask_run_options`) and others can be added over time. Notice that many of these are simply passed on to `self.enable_dev_tools` - that’s because in Python the flask `server.run` command (called at the end of `app.run_server`) is normally only used in development, in production a more powerful server such as gunicorn is used, but a user may still want to enable devtools using a production server. You’re the expert on the new back end language, only you know if such a split makes sense. We don't want to write our own web server framework, you should be able to choose an existing one. Ideally this server should be easy to install on all major operating systems / platforms where your language is used, and for production scalability it should be able to run multiple workers or otherwise make full use of a multi-core machine. If it has the ability in development mode to create friendly error messages with stack traces to help debugging, that's a plus, but if not we can probably build that ourselves.
83+
Similarly the `app.run` (previously `app.run_server`) method has a lot of options, listed [here](https://github.com/plotly/dash/blob/357f22167d40ef00c92ff165aa6df23c622799f6/dash/dash.py#L1596-L1671) - again some are Python-specific (`flask_run_options`) and others can be added over time. Notice that many of these are simply passed on to `self.enable_dev_tools` - that’s because in Python the flask `server.run` command (called at the end of `app.run_server`) is normally only used in development, in production a more powerful server such as gunicorn is used, but a user may still want to enable devtools using a production server. You’re the expert on the new back end language, only you know if such a split makes sense. We don't want to write our own web server framework, you should be able to choose an existing one. Ideally this server should be easy to install on all major operating systems / platforms where your language is used, and for production scalability it should be able to run multiple workers or otherwise make full use of a multi-core machine. If it has the ability in development mode to create friendly error messages with stack traces to help debugging, that's a plus, but if not we can probably build that ourselves.
8484

8585
## Contributing your own backends
8686

dash/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
get_relative_path,
2727
strip_relative_path,
2828
)
29+
2930
ctx = callback_context

dash/dash.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ def enable_dev_tools(
16301630
dev_tools_silence_routes_logging=None,
16311631
dev_tools_prune_errors=None,
16321632
):
1633-
"""Activate the dev tools, called by `run_server`. If your application
1633+
"""Activate the dev tools, called by `run`. If your application
16341634
is served by wsgi and you want to activate the dev tools, you can call
16351635
this method out of `__main__`.
16361636
@@ -1653,7 +1653,7 @@ def enable_dev_tools(
16531653
:param debug: Enable/disable all the dev tools unless overridden by the
16541654
arguments or environment variables. Default is ``True`` when
16551655
``enable_dev_tools`` is called directly, and ``False`` when called
1656-
via ``run_server``. env: ``DASH_DEBUG``
1656+
via ``run``. env: ``DASH_DEBUG``
16571657
:type debug: bool
16581658
16591659
:param dev_tools_ui: Show the dev tools UI. env: ``DASH_UI``
@@ -1891,7 +1891,7 @@ def delete_resource(resources):
18911891
# pylint: disable=protected-access
18921892
delete_resource(self.css._resources._resources)
18931893

1894-
def run_server(
1894+
def run(
18951895
self,
18961896
host=os.getenv("HOST", "127.0.0.1"),
18971897
port=os.getenv("PORT", "8050"),
@@ -1937,7 +1937,7 @@ def run_server(
19371937
:param debug: Enable/disable all the dev tools unless overridden by the
19381938
arguments or environment variables. Default is ``True`` when
19391939
``enable_dev_tools`` is called directly, and ``False`` when called
1940-
via ``run_server``. env: ``DASH_DEBUG``
1940+
via ``run``. env: ``DASH_DEBUG``
19411941
:type debug: bool
19421942
19431943
:param dev_tools_ui: Show the dev tools UI. env: ``DASH_UI``
@@ -2055,3 +2055,11 @@ def verify_url_part(served_part, url_part, part_name):
20552055
extra_files.append(path)
20562056

20572057
self.server.run(host=host, port=port, debug=debug, **flask_run_options)
2058+
2059+
def run_server(self, *args, **kwargs):
2060+
"""`run_server` is a deprecated alias of `run` and may be removed in a
2061+
future version. We recommend using `app.run` instead.
2062+
2063+
See `app.run` for usage information.
2064+
"""
2065+
self.run(*args, **kwargs)

dash/testing/application_runners.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def run():
167167
self.port = options["port"]
168168

169169
try:
170-
app.run_server(threaded=True, **options)
170+
app.run(threaded=True, **options)
171171
except SystemExit:
172172
logger.info("Server stopped")
173173

tests/unit/test_configs.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_invalid_strip_relative_path(prefix, partial_path):
320320
def test_port_env_fail_str(empty_environ):
321321
app = Dash()
322322
with pytest.raises(Exception) as excinfo:
323-
app.run_server(port="garbage")
323+
app.run(port="garbage")
324324
assert (
325325
excinfo.exconly()
326326
== "ValueError: Expecting an integer from 1 to 65535, found port='garbage'"
@@ -330,14 +330,14 @@ def test_port_env_fail_str(empty_environ):
330330
def test_port_env_fail_range(empty_environ):
331331
app = Dash()
332332
with pytest.raises(Exception) as excinfo:
333-
app.run_server(port="0")
333+
app.run(port="0")
334334
assert (
335335
excinfo.exconly()
336336
== "AssertionError: Expecting an integer from 1 to 65535, found port=0"
337337
)
338338

339339
with pytest.raises(Exception) as excinfo:
340-
app.run_server(port="65536")
340+
app.run(port="65536")
341341
assert (
342342
excinfo.exconly()
343343
== "AssertionError: Expecting an integer from 1 to 65535, found port=65536"
@@ -357,7 +357,7 @@ def test_no_proxy_success(mocker, caplog, empty_environ, setlevel_warning):
357357
# mock out the run method so we don't actually start listening forever
358358
mocker.patch.object(app.server, "run")
359359

360-
app.run_server(port=8787)
360+
app.run(port=8787)
361361

362362
STARTUP_MESSAGE = "Dash is running on http://127.0.0.1:8787/\n"
363363
if setlevel_warning:
@@ -381,7 +381,7 @@ def test_proxy_success(mocker, caplog, empty_environ, proxy, host, port, path):
381381
app = Dash(url_base_pathname=path)
382382
mocker.patch.object(app.server, "run")
383383

384-
app.run_server(proxy=proxystr, host=host, port=port)
384+
app.run(proxy=proxystr, host=host, port=port)
385385

386386
assert "Dash is running on {}{}\n".format(proxy, path) in caplog.text
387387

@@ -394,23 +394,21 @@ def test_proxy_failure(mocker, empty_environ):
394394
mocker.patch.object(app.server, "run")
395395

396396
with pytest.raises(_exc.ProxyError) as excinfo:
397-
app.run_server(
397+
app.run(
398398
proxy="https://127.0.0.1:8055::http://plot.ly", host="127.0.0.1", port=8055
399399
)
400400
assert "protocol: http is incompatible with the proxy" in excinfo.exconly()
401401
assert "you must use protocol: https" in excinfo.exconly()
402402

403403
with pytest.raises(_exc.ProxyError) as excinfo:
404-
app.run_server(
404+
app.run(
405405
proxy="http://0.0.0.0:8055::http://plot.ly", host="127.0.0.1", port=8055
406406
)
407407
assert "host: 127.0.0.1 is incompatible with the proxy" in excinfo.exconly()
408408
assert "you must use host: 0.0.0.0" in excinfo.exconly()
409409

410410
with pytest.raises(_exc.ProxyError) as excinfo:
411-
app.run_server(
412-
proxy="http://0.0.0.0:8155::http://plot.ly", host="0.0.0.0", port=8055
413-
)
411+
app.run(proxy="http://0.0.0.0:8155::http://plot.ly", host="0.0.0.0", port=8055)
414412
assert "port: 8055 is incompatible with the proxy" in excinfo.exconly()
415413
assert "you must use port: 8155" in excinfo.exconly()
416414

0 commit comments

Comments
 (0)