From: Marko Novak <mnovak@vosko.nl>
Date: Tue, 18 Nov 2025 10:55:14 +0100
Subject: Fix Python 3.11 compatibility

Origin: other, https://github.com/diddi-/flask-seeder/pull/21
Bug: https://github.com/diddi-/flask-seeder/issues/20
Bug-Debian: https://bugs.debian.org/1125850
Last-Update: 2026-02-09
---
 flask_seeder/generator.py         | 16 +++++++++++-----
 setup.py                          |  1 +
 tests/generator/test_generator.py |  7 ++++---
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/flask_seeder/generator.py b/flask_seeder/generator.py
index dc79763..93fe13c 100644
--- a/flask_seeder/generator.py
+++ b/flask_seeder/generator.py
@@ -1,11 +1,16 @@
 """ Generators module """
 
-import uuid
 import random
-import pkg_resources
+import sys
+import uuid
 
 from flask_seeder.parser import SGParser, Tokenizer
 
+if sys.version_info >= (3, 9):
+    import importlib.resources as importlib_resources
+else:
+    import importlib_resources
+
 def resource_path(path):
     """ Get the resource path
 
@@ -16,7 +21,7 @@ def resource_path(path):
         Returns the full filesystem path to the resource.
         Note that no validation is made to ensure the resource actually exist.
     """
-    return pkg_resources.resource_filename("flask_seeder", "data/" + path)
+    return importlib_resources.files("flask_seeder") / ("data/" + path)
 
 def read_resource(path):
     """ Read resource text file
@@ -30,8 +35,9 @@ def read_resource(path):
         A list with the file contents.
     """
     lines = []
-    with open(resource_path(path)) as source:
-        lines = source.read().splitlines()
+    with importlib_resources.as_file(resource_path(path)) as ref:
+        with open(ref) as source:
+            lines = source.read().splitlines()
 
     return lines
 
diff --git a/setup.py b/setup.py
index c20f2fd..2a74859 100755
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,7 @@ setuptools.setup(
     license="MIT",
     install_requires=[
         "Flask>=1.0.2",
+        "importlib_resources ; python_version<'3.9'"
     ],
     classifiers=[
         "Programming Language :: Python :: 3",
diff --git a/tests/generator/test_generator.py b/tests/generator/test_generator.py
index 1c08061..dbbbca2 100644
--- a/tests/generator/test_generator.py
+++ b/tests/generator/test_generator.py
@@ -1,3 +1,4 @@
+from pathlib import Path
 from unittest import TestCase
 from unittest.mock import MagicMock, patch, mock_open
 
@@ -16,13 +17,13 @@ class TestGenerator(TestCase):
         with self.assertRaises(NotImplementedError):
             self.generator.generate()
 
-    @patch("flask_seeder.generator.pkg_resources")
+    @patch("flask_seeder.generator.importlib_resources")
     def test_resource_path(self, m_pkg):
         resource_path("test")
 
-        m_pkg.resource_filename.assert_called_once()
+        m_pkg.files.assert_called_once()
 
-    @patch("flask_seeder.generator.resource_path", return_value="test")
+    @patch("flask_seeder.generator.resource_path", return_value=Path("test"))
     @patch("flask_seeder.generator.open", mock_open(read_data=MOCK_CONTENTS))
     def test_read_resource_return_contents_as_list(self, m_open):
         expected = [
