Blob Blame History Raw
From e4669a61a678827aa07d57b8a31d11e39b7cd550 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Dequ=C3=A8nes=20=28Duck=29?= <duck@redhat.com>
Date: Tue, 10 Mar 2020 18:22:26 +0900
Subject: [PATCH] use either importlib_resources or directly
 importlib.resources if available

---
 setup.py                        |  4 +++-
 src/mailman/__init__.py         | 11 +++++++++++
 src/mailman/testing/__init__.py | 11 +++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 242042102..b26c3e0d4 100644
--- a/setup.py
+++ b/setup.py
@@ -113,7 +113,6 @@ case second 'm'.  Any other spelling is incorrect.""",
         'flufl.bounce',
         'flufl.i18n>=2.0',
         'flufl.lock>=3.1',
-        'importlib_resources',
         'lazr.config',
         'passlib',
         'requests',
@@ -123,6 +122,9 @@ case second 'm'.  Any other spelling is incorrect.""",
         'zope.event',
         'zope.interface',
         ],
+    extras_require = {
+        'importlib_resources': ['importlib_resources'],
+        },
     )
 
 # flake8: noqa
diff --git a/src/mailman/__init__.py b/src/mailman/__init__.py
index 833f8f6b2..36716a188 100644
--- a/src/mailman/__init__.py
+++ b/src/mailman/__init__.py
@@ -37,3 +37,14 @@ if 'build_sphinx' not in sys.argv:                  # pragma: nocover
     else:
         from mailman.core.i18n import initialize
     initialize()
+
+try:
+    import importlib.resources
+    sys.modules['importlib_resources'] = importlib.resources
+except ImportError:
+    try:
+        import importlib_resources
+    except ImportError:
+        print("Either importlib_resources library is needed or Python >=3.7", file=sys.stderr)
+        sys.exit(1)
+
diff --git a/src/mailman/testing/__init__.py b/src/mailman/testing/__init__.py
index e69de29bb..82c06b898 100644
--- a/src/mailman/testing/__init__.py
+++ b/src/mailman/testing/__init__.py
@@ -0,0 +1,11 @@
+try:
+    import importlib.resources
+    import sys
+    sys.modules['importlib_resources'] = importlib.resources
+except ImportError:
+    try:
+        import importlib_resources
+    except ImportError:
+        print("Either importlib_resources library is needed or Python >=3.7", file=sys.stderr)
+        sys.exit(1)
+
-- 
2.25.1