From a7eb3faf96e3535f197a8f748648b9cfc57a9d52 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 18 Jul 2019 01:08:09 -0700 Subject: [PATCH] storage: Move the staticfiles.json hack to ZulipStorage. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no reason to monkey-patch something that we were already subclassing. Removing the PRODUCTION conditional causes us to generate staticfiles.json in the right place to begin with so we don’t need to move it later. It also allows Django to find staticfiles.json if running the dev server with PIPELINE_ENABLED. Signed-off-by: Anders Kaseorg --- tools/update-prod-static | 5 ----- zerver/lib/storage.py | 18 ++++++------------ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tools/update-prod-static b/tools/update-prod-static index 6d633b0f35..96d415f55e 100755 --- a/tools/update-prod-static +++ b/tools/update-prod-static @@ -5,7 +5,6 @@ import os import argparse -import shutil import sys # We need settings so we can figure out where the prod-static directory is. @@ -65,10 +64,6 @@ run(['./manage.py', 'collectstatic', '--no-default-ignore', '--noinput', '-i', 'assets', '-i', 'js', '-i', 'styles', '-i', 'templates'], stdout=fp, stderr=fp) -if not settings.PRODUCTION: - # When building a release tarball, we need to move staticfiles.json - shutil.move('prod-static/serve/staticfiles.json', 'staticfiles.json') - # Compile translation strings to generate `.mo` files. run(['./manage.py', 'compilemessages'], stdout=fp, stderr=fp) diff --git a/zerver/lib/storage.py b/zerver/lib/storage.py index 5edfdeba09..039386090d 100644 --- a/zerver/lib/storage.py +++ b/zerver/lib/storage.py @@ -35,22 +35,16 @@ class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage): return name return super().hashed_name(name, content, filename) -if settings.PRODUCTION: +class ZulipStorage(PipelineMixin, + IgnoreBundlesManifestStaticFilesStorage): # This is a hack to use staticfiles.json from within the # deployment, rather than a directory under STATIC_ROOT. By doing # so, we can use a different copy of staticfiles.json for each # deployment, which ensures that we always use the correct static # assets for each deployment. - ManifestStaticFilesStorage.manifest_name = os.path.join(settings.DEPLOY_ROOT, - "staticfiles.json") - orig_path = ManifestStaticFilesStorage.path + manifest_name = os.path.join(settings.DEPLOY_ROOT, "staticfiles.json") - def path(self: ManifestStaticFilesStorage, name: str) -> str: - if name == ManifestStaticFilesStorage.manifest_name: + def path(self, name: str) -> str: + if name == self.manifest_name: return name - return orig_path(self, name) - ManifestStaticFilesStorage.path = path - -class ZulipStorage(PipelineMixin, - IgnoreBundlesManifestStaticFilesStorage): - pass + return super().path(name)