Skip to content

Commit 2a3a810

Browse files
committed
Switch to using whitenoise instead of Werkzeug for static files
1 parent 6f746ad commit 2a3a810

27 files changed

+25
-22
lines changed

config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
FileUtils.rm(Dir["warehouse/static/compiled/**/#{File.basename(rel3)}-*#{File.extname(rel2)}"])
2424

2525
system('wake') or raise("There was an error running wake") # TODO: Figure out how to do this better
26+
27+
system('python -m whitenoise.gzip -q warehouse/static/compiled')
2628
end

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ requires-dist =
2424
SQLAlchemy
2525
sqlalchemy-citext>=1.2.0
2626
Werkzeug
27+
whitenoise>=0.11
2728

2829
psycopg2; platform_python_implementation == 'CPython'
2930
psycopg2cffi; platform_python_implementation == 'PyPy'

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def recursive_glob(path, pattern, cutdirs=0):
5353
"SQLAlchemy",
5454
"sqlalchemy-citext>=1.2.0",
5555
"Werkzeug",
56+
"whitenoise>=0.11",
5657
]
5758

5859
if platform.python_implementation() == "PyPy":

tests/test_application.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ def fake_view(*args, **kwargs):
154154

155155

156156
def test_static_middleware(monkeypatch):
157-
SharedDataMiddleware = pretend.call_recorder(lambda app, c: app)
157+
WhiteNoise = pretend.call_recorder(lambda app, root, prefix, max_age: app)
158158

159159
monkeypatch.setattr(
160160
application,
161-
"SharedDataMiddleware",
162-
SharedDataMiddleware,
161+
"WhiteNoise",
162+
WhiteNoise,
163163
)
164164

165165
Warehouse.from_yaml(
@@ -169,18 +169,18 @@ def test_static_middleware(monkeypatch):
169169
)),
170170
)
171171

172-
assert SharedDataMiddleware.calls == [
172+
assert WhiteNoise.calls == [
173173
pretend.call(
174174
mock.ANY,
175-
{
176-
"/static/": os.path.abspath(
177-
os.path.join(
178-
os.path.dirname(warehouse.__file__),
179-
"static",
180-
"compiled",
181-
),
175+
root=os.path.abspath(
176+
os.path.join(
177+
os.path.dirname(warehouse.__file__),
178+
"static",
179+
"compiled",
182180
),
183-
},
181+
),
182+
prefix="/static/",
183+
max_age=31557600,
184184
)
185185
]
186186

warehouse/application.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
from raven.middleware import Sentry
3838
from six.moves import urllib_parse
3939
from werkzeug.exceptions import HTTPException
40-
from werkzeug.wsgi import SharedDataMiddleware, responder
40+
from werkzeug.wsgi import responder
41+
from whitenoise import WhiteNoise
4142

4243
import warehouse
4344
import warehouse.cli
@@ -160,17 +161,15 @@ def __init__(self, config, engine=None, redis=None):
160161
self.wsgi_app = Sentry(self.wsgi_app, Client(**self.config.sentry))
161162

162163
# Serve the static files that are packaged as part of Warehouse
163-
self.wsgi_app = SharedDataMiddleware(
164+
self.wsgi_app = WhiteNoise(
164165
self.wsgi_app,
165-
{
166-
"/static/": os.path.abspath(
167-
os.path.join(
168-
os.path.dirname(warehouse.__file__),
169-
"static",
170-
"compiled",
171-
),
166+
root=os.path.abspath(
167+
os.path.join(
168+
os.path.dirname(warehouse.__file__), "static", "compiled",
172169
),
173-
},
170+
),
171+
prefix="/static/",
172+
max_age=31557600,
174173
)
175174

176175
def __call__(self, environ, start_response):
Binary file not shown.
16.3 KB
Binary file not shown.
Binary file not shown.
1.01 KB
Binary file not shown.
136 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
123 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
6.98 KB
Binary file not shown.
11.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
32.2 KB
Binary file not shown.
54.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)