Skip to content
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

Exception is raised with default settings if go dependency isn't installed #97

Closed
Levtastic opened this issue Jul 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Levtastic
Copy link

The description for the go option states

prefer go minifier, if optional go dependency is installed (default: True)

This suggests that if the go dependency is not installed, this option will do nothing. Instead, leaving this option as True causes the parsers to raise an exception from here:

if self.has_go_parser and not minify_go:
raise FlaskMinifyException(
f"Cannot use any Go parsers without installing "
"Go optional dependency: `pip install flask-minify[go]`"
)
@property
def has_go_parser(self):
return any(p.go for p in self.parsers.values())

If a user has a development environment that does not have the extension installed (for example, developing on windows) but still wishes to use the go extension in production, they must explicitly toggle this option based on the code environment, which isn't ideal.

Instead it would be nice if this option was ignored if the go dependency isn't found, as its description suggests it is.

In case it helps anyone else, my current workaround is:

from flask_minify import Minify, parsers
Minify(app, go=bool(parsers.minify_go))

But if it suits your deploy process, you could also do the much simpler:

Minify(app, go=not app.debug)
@mrf345 mrf345 added the bug Something isn't working label Jul 14, 2024
@mrf345 mrf345 self-assigned this Jul 14, 2024
@mrf345
Copy link
Owner

mrf345 commented Jul 14, 2024

Nice catch, and thanks for the thorough description. Should be resolved in 0.48
I've added a few tests to cover this scenario d100773

@mrf345 mrf345 closed this as completed in 86aa603 Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants