summarylogtreecommitdiffstats
path: root/pkg_resources.patch
blob: de3654919fff03ce5631aa75748ead8cc5583662 (plain)
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
diff --git a/sassutils/wsgi.py b/sassutils/wsgi.py
index d29fa824f353..f2232b88232f 100644
--- a/sassutils/wsgi.py
+++ b/sassutils/wsgi.py
@@ -6,7 +6,18 @@ import collections.abc
 import logging
 import os.path
 
-from pkg_resources import resource_filename
+# For getting resources filenames, we now use importlib.resources
+from contextlib import ExitStack
+from sys import version_info
+
+# However, we check the Python version in order to still support older
+# versions which don't support importlib.resources (backwards compatibility)
+if version_info >= (3, 7):
+    # Use importlib.resources for Python 3.7 and later
+    from importlib import resources
+else:
+    # Use importlib_resources for Python 3.6 and earlier
+    import importlib_resources as resources
 
 from .builder import Manifest
 from sass import CompileError
@@ -107,7 +118,9 @@ class SassMiddleware:
         for package_name in self.manifests:
             if package_name in self.package_dir:
                 continue
-            path = resource_filename(package_name, '')
+            ref = resources.files(package_name) / 'resource.dat'
+            with resources.as_file(ref) as res_path:
+                path = res_path
             self.package_dir[package_name] = path
         self.paths = []
         for package_name, manifest in self.manifests.items():