Skip to content

Commit

Permalink
Move flask_compress dependency to extra requires.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Oct 27, 2022
1 parent a966208 commit 3d18085
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
39 changes: 23 additions & 16 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from textwrap import dedent

import flask
from flask_compress import Compress

from pkg_resources import get_distribution, parse_version

Expand Down Expand Up @@ -69,9 +68,6 @@
_parse_query_string,
)


_flask_compress_version = parse_version(get_distribution("flask-compress").version)

# Add explicit mapping for map files
mimetypes.add_type("application/json", ".map", True)

Expand Down Expand Up @@ -261,6 +257,7 @@ class Dash:
:type serve_locally: boolean
:param compress: Use gzip to compress files and data served by Flask.
To use this option, you need to install dash[compress]
Default ``False``
:type compress: boolean
Expand Down Expand Up @@ -379,16 +376,6 @@ def __init__( # pylint: disable=too-many-statements
else:
raise ValueError("server must be a Flask app or a boolean")

if (
self.server is not None
and not hasattr(self.server.config, "COMPRESS_ALGORITHM")
and _flask_compress_version >= parse_version("1.6.0")
):
# flask-compress==1.6.0 changed default to ['br', 'gzip']
# and non-overridable default compression with Brotli is
# causing performance issues
self.server.config["COMPRESS_ALGORITHM"] = ["gzip"]

base_prefix, routes_prefix, requests_prefix = pathname_configs(
url_base_pathname, routes_pathname_prefix, requests_pathname_prefix
)
Expand Down Expand Up @@ -540,8 +527,28 @@ def init_app(self, app=None, **kwargs):
)

if config.compress:
# gzip
Compress(self.server)
try:
# pylint: disable=import-outside-toplevel
from flask_compress import Compress

# gzip
Compress(self.server)

_flask_compress_version = parse_version(
get_distribution("flask-compress").version
)

if not hasattr(
self.server.config, "COMPRESS_ALGORITHM"
) and _flask_compress_version >= parse_version("1.6.0"):
# flask-compress==1.6.0 changed default to ['br', 'gzip']
# and non-overridable default compression with Brotli is
# causing performance issues
self.server.config["COMPRESS_ALGORITHM"] = ["gzip"]
except ImportError as error:
raise ImportError(
"To use the compress option, you need to install dash[compress]"
) from error

@self.server.errorhandler(PreventUpdate)
def _handle_error(_):
Expand Down
1 change: 1 addition & 0 deletions requires-compress.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask-compress
1 change: 0 additions & 1 deletion requires-install.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Flask>=1.0.4
flask-compress
plotly>=5.0.0
dash_html_components==2.0.0
dash_core_components==2.0.0
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def read_req_file(req_type):
"testing": read_req_file("testing"),
"celery": read_req_file("celery"),
"diskcache": read_req_file("diskcache"),
"compress": read_req_file("compress"),
},
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 3d18085

Please sign in to comment.