Skip to content

Commit c1d5c02

Browse files
committed
dim/models: replace deprecated pkg_resources
replace `pkg_resources` with `importlib.resources` according to the migration guide https://importlib-resources.readthedocs.io/en/latest/migration.html
1 parent b39692e commit c1d5c02

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

dim/dim/models/migrate.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
from collections import deque
66

7-
import pkg_resources
7+
import importlib.resources
88

99
from dim.models import SchemaInfo, SCHEMA_VERSION, db
1010

@@ -38,11 +38,11 @@ def migrate():
3838

3939
def gather_graph():
4040
graph = {}
41-
for script in pkg_resources.resource_listdir('dim', 'sql'):
42-
m = re.match(r'(migrate|rollback)_(.*)_to_(.*).sql', script)
41+
for script in importlib.resources.files("dim").joinpath("sql").iterdir():
42+
m = re.match(r'(migrate|rollback)_(.*)_to_(.*).sql', script.name)
4343
if m:
4444
x, y = m.group(2), m.group(3)
45-
graph.setdefault(x, []).append((y, script))
45+
graph.setdefault(x, []).append((y, script.name))
4646
return graph
4747

4848

@@ -59,5 +59,7 @@ def run_script(new_version, script):
5959
cmd.append('-u%s' % url.username)
6060
if url.password:
6161
cmd.append('-p%s' % url.password)
62-
stdin = open(pkg_resources.resource_filename('dim', 'sql/' + script))
63-
subprocess.check_call(cmd, stdin=stdin)
62+
ref = importlib.resources.files("dim") / "sql" / script
63+
with importlib.resources.as_file(ref) as path:
64+
with open(path) as stdin:
65+
subprocess.check_call(cmd, stdin=stdin)

0 commit comments

Comments
 (0)