Fixes Issues #94 #96

pkg_resources is deprecated see: https://setuptools.pypa.io/en/latest/pkg_resources.html
This throws a warning on every currently supported python version.
Additionally this breaks yoyo migrate if not manually installed setuptools, which currently isn't a dependcy.

This PR remove the dependency to pkg_resources resolving this issue.
1 files changed, 12 insertions(+), 15 deletions(-)

M yoyo/migrations.py
M yoyo/migrations.py +12 -15
@@ 31,7 31,7 @@ import inspect
 import types
 import textwrap
 
-import pkg_resources
+from importlib.resources import files
 import sqlparse
 
 from yoyo import exceptions

          
@@ 133,7 133,6 @@ def read_sql_migration(
 
 
 class Migration(object):
-
     __all_migrations: t.Dict[str, "Migration"] = {}
 
     def __init__(self, id, path, source_dir):

          
@@ 235,7 234,6 @@ class Migration(object):
         self.steps = collector.create_steps(self.use_transactions)
 
     def process_steps(self, backend, direction, force=False):
-
         self.load()
         reverse = {"rollback": "apply", "apply": "rollback"}[direction]
 

          
@@ 280,7 278,6 @@ class PostApplyHookMigration(Migration):
 
 
 class StepBase(object):
-
     id = None
 
     def __repr__(self):

          
@@ 359,7 356,6 @@ class MigrationStep(StepBase):
     """
 
     def __init__(self, id, apply, rollback):
-
         self.id = id
         self._rollback = rollback
         self._apply = apply

          
@@ 455,16 451,17 @@ def _expand_sources(sources) -> t.Iterab
         if mo:
             package_name = mo.group(1)
             resource_dir = mo.group(2)
-            paths = [
-                pkg_resources.resource_filename(
-                    package_name, "{}/{}".format(resource_dir, f)
-                )
-                for f in sorted(
-                    pkg_resources.resource_listdir(package_name, resource_dir)
-                )
-                if _is_migration_file(f)
-            ]
-            yield (source, paths)
+            try:
+                pkg_files = files(package_name).joinpath(resource_dir)
+                if pkg_files.is_dir():
+                    paths = [
+                        str(file)
+                        for file in sorted(pkg_files.iterdir())
+                        if _is_migration_file(file.name)
+                    ]
+                    yield (source, paths)
+            except FileNotFoundError:
+                continue
         else:
             for directory in glob(source):
                 paths = [