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

Changable compressor class #354

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PetrDlouhy
Copy link

@PetrDlouhy PetrDlouhy commented Feb 4, 2022

Fixes #279.

@PetrDlouhy PetrDlouhy force-pushed the changable_compressor_class branch 2 times, most recently from c114d60 to 128b704 Compare February 4, 2022 14:12
@dulacp
Copy link

dulacp commented Sep 9, 2022

@adamchainz could this be merged once rebase? I think this feature would be great to give users flexibility.
@PetrDlouhy, if yes, could you rebase your PR?

Copy link
Collaborator

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

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

I haven't thought too hard about whether this is a good solution. It's a large API area to expose to users.

The PR is also far from ready: there are no tests, the documentation needs expanding significantly to describe how to subclass Compressor and what methods can be customized, there are no non-django docs, and there's no changelog entry.

I would also like to see some evidence of experimentation with alternative approaches, even just monkey-patching the current version of Whitenoise to see how easy it is to skip files that way.

Comment on lines 129 to 136
try:
compressor_class = import_string(
getattr(
settings, "WHITENOISE_COMPRESSOR_CLASS", "whitenoise.compress.Compressor"
),
)
except ImproperlyConfigured:
compressor_class = Compressor
Copy link
Collaborator

Choose a reason for hiding this comment

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

reading settings at import time is not generally safe in Django, since they can still be overriden, in e.g. tests or by later configuration settings loading. Only read the setting at runtime

Copy link
Author

Choose a reason for hiding this comment

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

This should be fixed.

@PetrDlouhy PetrDlouhy force-pushed the changable_compressor_class branch 3 times, most recently from 9335692 to 0fec8c0 Compare February 22, 2024 07:52
@PetrDlouhy
Copy link
Author

@adamchainz I have rebased to current main and dealt with the settings problem.

Have you made some decision whether you want this in the project or not? I would like to work on the tests and documentation, but I don't want to waste my time if it doesn't eventually get merged.

I would also like to see some evidence of experimentation with alternative approaches, even just monkey-patching the current version of Whitenoise to see how easy it is to skip files that way.

I am not sure how to deal with this. Of course it would be possible with monkey-patching, but it would be possible, but it would be very ugly.
Different approach might be to allow to only override the should_compress() method.

"whitenoise.compress.Compressor",
),
)
except ImproperlyConfigured:
Copy link

Choose a reason for hiding this comment

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

Is this still needed now that the settings import is inside a function?
I worry that it would hide legitimate problems without any notice to the dev.

Copy link
Author

Choose a reason for hiding this comment

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

@merwok You are right. I fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow compression with many files - add skip patterns settings
4 participants