about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/thumbor/0001-Don-t-use-which-implementation-to-find-required-exec.patch
blob: 4a2d9df06181c3541adfcc87947901615a5d9101 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
From bd5a5b58b438ff34d27781e28cd7fab93bfc9f3f Mon Sep 17 00:00:00 2001
From: Maximilian Bosch <maximilian@mbosch.me>
Date: Sat, 9 Mar 2019 23:26:30 +0100
Subject: [PATCH] Don't use `which` implementation to find required executables

Nix specific patch.

Rather than relying on a global state, we set an absolute store path for
all external dependencies to ensure their functionality.
---
 integration_tests/__init__.py       |  4 ++--
 tests/engines/test_gif.py           |  2 +-
 tests/handlers/test_base_handler.py | 30 ++++++++++++++---------------
 tests/optimizers/test_gifv.py       |  2 +-
 tests/test_server.py                |  4 ++++
 tests/test_utils.py                 |  3 +++
 thumbor/server.py                   |  7 +------
 7 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/integration_tests/__init__.py b/integration_tests/__init__.py
index 9bdd0a3..7d9de8f 100644
--- a/integration_tests/__init__.py
+++ b/integration_tests/__init__.py
@@ -15,7 +15,7 @@ class EngineCase(AsyncHTTPTestCase):
     def get_app(self):
         cfg = Config(SECURITY_KEY='ACME-SEC')
         server_params = ServerParameters(None, None, None, None, None, None)
-        server_params.gifsicle_path = which('gifsicle')
+        server_params.gifsicle_path = '@gifsicle@'
 
         cfg.DETECTORS = [
             'thumbor.detectors.face_detector',
@@ -28,7 +28,7 @@ class EngineCase(AsyncHTTPTestCase):
         cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'imgs')
         cfg.ENGINE = getattr(self, 'engine', None)
         cfg.USE_GIFSICLE_ENGINE = True
-        cfg.FFMPEG_PATH = which('ffmpeg')
+        cfg.FFMPEG_PATH = '@ffmpeg@'
         cfg.ENGINE_THREADPOOL_SIZE = 10
         cfg.OPTIMIZERS = [
             'thumbor.optimizers.gifv',
diff --git a/tests/engines/test_gif.py b/tests/engines/test_gif.py
index c0c8430..ce0cc51 100644
--- a/tests/engines/test_gif.py
+++ b/tests/engines/test_gif.py
@@ -44,7 +44,7 @@ class GitEngineTestCase(TestCase):
     def get_server(self):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
-        server.gifsicle_path = which('gifsicle')
+        server.gifsicle_path = '@gifsicle@'
         return server
 
     def get_context(self, *args, **kwargs):
diff --git a/tests/handlers/test_base_handler.py b/tests/handlers/test_base_handler.py
index 69dc110..4493abe 100644
--- a/tests/handlers/test_base_handler.py
+++ b/tests/handlers/test_base_handler.py
@@ -557,7 +557,7 @@ class ImageOperationsWithAutoWebPTestCase(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     def get_as_webp(self, url):
@@ -657,7 +657,7 @@ class ImageOperationsWithAutoWebPWithResultStorageTestCase(BaseImagingTestCase):
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
         ctx.request = self.get_request()
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     @property
@@ -783,7 +783,7 @@ class ImageOperationsWithGifVTestCase(BaseImagingTestCase):
         cfg = Config(SECURITY_KEY='ACME-SEC')
         cfg.LOADER = "thumbor.loaders.file_loader"
         cfg.FILE_LOADER_ROOT_PATH = self.loader_path
-        cfg.FFMPEG_PATH = which('ffmpeg')
+        cfg.FFMPEG_PATH = '@ffmpeg@'
         cfg.OPTIMIZERS = [
             'thumbor.optimizers.gifv',
         ]
@@ -793,7 +793,7 @@ class ImageOperationsWithGifVTestCase(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     def test_should_convert_animated_gif_to_mp4_when_filter_without_params(self):
@@ -828,7 +828,7 @@ class ImageOperationsImageCoverTestCase(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     def test_can_get_image_cover(self):
@@ -849,7 +849,7 @@ class ImageOperationsWithResultStorageTestCase(BaseImagingTestCase):
         cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
 
         cfg.USE_GIFSICLE_ENGINE = True
-        cfg.FFMPEG_PATH = which('ffmpeg')
+        cfg.FFMPEG_PATH = '@ffmpeg@'
         cfg.AUTO_WEBP = True
         cfg.OPTIMIZERS = [
             'thumbor.optimizers.gifv',
@@ -860,7 +860,7 @@ class ImageOperationsWithResultStorageTestCase(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
 
         return ctx
 
@@ -891,7 +891,7 @@ class ImageOperationsResultStorageOnlyTestCase(BaseImagingTestCase):
         cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
         cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
         cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
-        cfg.FFMPEG_PATH = which('ffmpeg')
+        cfg.FFMPEG_PATH = '@ffmpeg@'
 
         cfg.USE_GIFSICLE_ENGINE = True
         cfg.AUTO_WEBP = True
@@ -904,7 +904,7 @@ class ImageOperationsResultStorageOnlyTestCase(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
 
         return ctx
 
@@ -1040,7 +1040,7 @@ class ImageOperationsWithMaxPixels(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     def test_should_error(self):
@@ -1061,7 +1061,7 @@ class ImageOperationsWithRespectOrientation(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         self.context = Context(server, cfg, importer)
-        self.context.server.gifsicle_path = which('gifsicle')
+        self.context.server.gifsicle_path = '@gifsicle@'
         return self.context
 
     def test_should_be_ok_when_orientation_exif(self):
@@ -1153,7 +1153,7 @@ class ImageOperationsWithJpegtranTestCase(BaseImagingTestCase):
         cfg = Config(SECURITY_KEY='ACME-SEC')
         cfg.LOADER = "thumbor.loaders.file_loader"
         cfg.FILE_LOADER_ROOT_PATH = self.loader_path
-        cfg.JPEGTRAN_PATH = which('jpegtran')
+        cfg.JPEGTRAN_PATH = '@jpegtran@'
         cfg.PROGRESSIVE_JPEG = True,
         cfg.RESULT_STORAGE_STORES_UNSAFE = True,
         cfg.OPTIMIZERS = [
@@ -1175,9 +1175,7 @@ class ImageOperationsWithJpegtranTestCase(BaseImagingTestCase):
         f.write(response.body)
         f.close()
 
-        exiftool = which('exiftool')
-        if not exiftool:
-            raise AssertionError('exiftool was not found. Please install it to run thumbor\'s tests.')
+        exiftool = '@exiftool@'
 
         command = [
             exiftool,
@@ -1221,7 +1219,7 @@ class ImageOperationsWithoutStorage(BaseImagingTestCase):
         server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
         server.security_key = 'ACME-SEC'
         ctx = Context(server, cfg, importer)
-        ctx.server.gifsicle_path = which('gifsicle')
+        ctx.server.gifsicle_path = '@gifsicle@'
         return ctx
 
     def test_meta(self):
diff --git a/tests/optimizers/test_gifv.py b/tests/optimizers/test_gifv.py
index 229e9cd..066f2d5 100644
--- a/tests/optimizers/test_gifv.py
+++ b/tests/optimizers/test_gifv.py
@@ -31,7 +31,7 @@ class GifvOptimizerTest(TestCase):
     def get_context(self):
         conf = Config()
         conf.STATSD_HOST = ''
-        conf.FFMPEG_PATH = which('ffmpeg')
+        conf.FFMPEG_PATH = '@ffmpeg@'
         ctx = Context(config=conf)
         ctx.request = RequestParameters()
         ctx.request.filters.append('gifv')
diff --git a/tests/test_server.py b/tests/test_server.py
index 5b31750..c2a65dc 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -11,6 +11,8 @@
 from unittest import TestCase
 import mock
 
+from nose.tools import nottest
+
 from preggy import expect
 
 from thumbor.app import ThumborServiceApp
@@ -118,6 +120,7 @@ class ServerTestCase(TestCase):
         expect(server_parameters.security_key).to_equal('something')
 
     @mock.patch.object(thumbor.server, 'which')
+    @nottest
     def test_validate_gifsicle_path(self, which_mock):
         server_parameters = mock.Mock(security_key=None)
         conf = Config(SECURITY_KEY='test', USE_GIFSICLE_ENGINE=True)
@@ -128,6 +131,7 @@ class ServerTestCase(TestCase):
         expect(server_parameters.gifsicle_path).to_equal('/usr/bin/gifsicle')
 
     @mock.patch.object(thumbor.server, 'which')
+    @nottest
     def test_validate_null_gifsicle_path(self, which_mock):
         server_parameters = mock.Mock(security_key=None)
         conf = Config(SECURITY_KEY='test', USE_GIFSICLE_ENGINE=True)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 38cd51b..7dd0b3e 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -10,6 +10,7 @@
 
 from mock import Mock, patch
 from unittest import TestCase
+from nose.tools import nottest
 import logging
 
 from preggy import expect
@@ -112,6 +113,7 @@ class UtilsTestCase(TestCase):
             test_func()
             mock_warn.assert_called_once_with('Deprecated function test_func: func2')
 
+    @nottest
     def test_can_which_by_path(self):
         result = which('/bin/ls')
         expect(result).to_equal('/bin/ls')
@@ -119,6 +121,7 @@ class UtilsTestCase(TestCase):
         result = which('/tmp')
         expect(result).to_be_null()
 
+    @nottest
     def test_can_which_by_env(self):
         result = which('ls')
         expect(result).to_equal('/bin/ls')
diff --git a/thumbor/server.py b/thumbor/server.py
index c75a769..821163b 100644
--- a/thumbor/server.py
+++ b/thumbor/server.py
@@ -89,12 +89,7 @@ def validate_config(config, server_parameters):
         warnings.simplefilter('error', Image.DecompressionBombWarning)
 
     if config.USE_GIFSICLE_ENGINE:
-        server_parameters.gifsicle_path = which('gifsicle')
-        if server_parameters.gifsicle_path is None:
-            raise RuntimeError(
-                'If using USE_GIFSICLE_ENGINE configuration to True, the `gifsicle` binary must be in the PATH '
-                'and must be an executable.'
-            )
+        server_parameters.gifsicle_path = '@gifsicle@'
 
 
 def get_context(server_parameters, config, importer):
-- 
2.18.1