# HG changeset patch
# User b3n4kh <b@akhras.at>
# Date 1714424587 -7200
# Mon Apr 29 23:03:07 2024 +0200
# Node ID b21e6753a7fe3d44f46255933a9700556f0a193f
# Parent 5875ba420a0e3e08c3f9b7022c821af0ee5659f7
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.
diff --git a/yoyo/migrations.py b/yoyo/migrations.py
--- a/yoyo/migrations.py
+++ b/yoyo/migrations.py
@@ -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 = [
Thanks, applied!