Skip to content

Fetch flask_compress version from __version__ module #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

europa502
Copy link

Fix for #1606

Added code to handle "pkg_resources.DistributionNotFound: The 'flask-compress' distribution was not found and is required by the application" while building app with cx_freeze.
Since version is included only in and above cx_freeze 1.10.0, I've added the try/except condition.

_flask_compress_version = parse_version(get_distribution("flask-compress").version)
except DistributionNotFound:
from flask_compress import __version__ as _flask_compress_version
_flask_compress_version = parse_version(_flask_compress_version)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, nice find! Unfortunately flask_compress.__version__ doesn't seem to exist until v1.10, which is probably why get_distribution was used in the first place.

I'd suggest a further fallback for the AttributeError: module 'flask_compress' has no attribute '__version__' you'll get before v1.10.0 that assumes it's maybe parse_version("1.9.0") (all that matters is >=1.6.0)

Another thing to note though: the default for compress was changed to False in Dash 2.0 (on the theory that for local dev this compression just slows things down, and for production deployments this is normally handled at a lower level like gunicorn). So this whole issue is irrelevant for most people as long as it doesn't error.

So if you're feeling adventurous, we could probably take this this whole block, plus the original from flask_compress import Compress AND the block where we use this to modify the server config:

dash/dash/dash.py

Lines 308 to 316 in b32ac95

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"]

and move it into the block where we actually turn compression on, so the only people who will hit any of this code will be those who explicitly enable compression, everyone else won't even import the module.

dash/dash/dash.py

Lines 453 to 455 in b32ac95

if config.compress:
# gzip
Compress(self.server)

If we do this we'll just want to manually check that you actually do get gzip compression with current flask_compress

@gvwilson gvwilson self-assigned this Jul 23, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P2 considered for next cycle fix fixes something broken community community contribution labels Aug 13, 2024
@ndrezn
Copy link
Member

ndrezn commented Aug 22, 2024

It looks like this issue was addressed independently in cx_freeze>=6.7, so closing this PR. It doesn't seem like an unreasonable change but it also doesn't appear to be a try/except we need to consider in Dash.

@ndrezn ndrezn closed this Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution fix fixes something broken P2 considered for next cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants