storage: Remove RemoveUnminifiedFilesMixin.

This can be done much more easily with the right options to
collectstatic.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-02 17:18:44 -07:00 committed by Tim Abbott
parent f47f98e2f1
commit b0a30aa01a
2 changed files with 2 additions and 25 deletions

View File

@ -57,7 +57,7 @@ run(['./tools/webpack'], stdout=fp, stderr=fp)
# Collect the files that we're going to serve; this creates prod-static/serve. # Collect the files that we're going to serve; this creates prod-static/serve.
run(['./manage.py', 'collectstatic', '--no-default-ignore', run(['./manage.py', 'collectstatic', '--no-default-ignore',
'--noinput', '-i', 'assets', '-i', 'styles', '-i', 'templates'], '--noinput', '-i', 'assets', '-i', 'js', '-i', 'styles', '-i', 'templates'],
stdout=fp, stderr=fp) stdout=fp, stderr=fp)
if not settings.PRODUCTION: if not settings.PRODUCTION:

View File

@ -1,34 +1,12 @@
# Useful reading is https://zulip.readthedocs.io/en/latest/subsystems/front-end-build-process.html # Useful reading is https://zulip.readthedocs.io/en/latest/subsystems/front-end-build-process.html
import os import os
import shutil from typing import Optional
from typing import Any, Dict, List, Optional, Tuple
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from pipeline.storage import PipelineMixin from pipeline.storage import PipelineMixin
class RemoveUnminifiedFilesMixin:
def post_process(self, paths: Dict[str, Tuple['ZulipStorage', str]], dry_run: bool=False,
**kwargs: Any) -> List[Tuple[str, str, bool]]:
if dry_run:
return []
root = settings.STATIC_ROOT
to_remove = ['js']
for tree in to_remove:
shutil.rmtree(os.path.join(root, tree))
is_valid = lambda p: all([not p.startswith(k) for k in to_remove])
paths = {k: v for k, v in paths.items() if is_valid(k)}
super_class = super()
if hasattr(super_class, 'post_process'):
return super_class.post_process(paths, dry_run, **kwargs) # type: ignore # https://github.com/python/mypy/issues/2956
return []
class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage): class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage):
def hashed_name(self, name: str, content: Optional[str]=None, filename: Optional[str]=None) -> str: def hashed_name(self, name: str, content: Optional[str]=None, filename: Optional[str]=None) -> str:
ext = os.path.splitext(name)[1] ext = os.path.splitext(name)[1]
@ -75,6 +53,5 @@ if settings.PRODUCTION:
ManifestStaticFilesStorage.path = path ManifestStaticFilesStorage.path = path
class ZulipStorage(PipelineMixin, class ZulipStorage(PipelineMixin,
RemoveUnminifiedFilesMixin,
IgnoreBundlesManifestStaticFilesStorage): IgnoreBundlesManifestStaticFilesStorage):
pass pass