Skip to content

Commit

Permalink
refactor: use importlib instead of pkg_resources (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Jun 3, 2024
1 parent 4b59a4b commit 3b6e4e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import sqlite3
from importlib import resources
from typing import Iterator, Optional, Union

import pkg_resources
import yoyo

from .._internal.translate import translate_alias_records, translate_api2db
Expand Down Expand Up @@ -239,11 +239,15 @@ def _upgrade_db(self) -> None:
db_url = "sqlite:///" + self._db_path
backend = yoyo.get_backend(db_url)
if __package__ is None:
raise ValueError("__package__ must be accessible to retrieve migration files")
migration_dir = pkg_resources.resource_filename(__package__, migration_path)
msg = (
"__package__ is None. This module must be part of a package to "
"resolve the migration files path."
)
raise ImportError(msg)
migration_dir = str(resources.files(__package__) / migration_path)
migrations = yoyo.read_migrations(migration_dir)
assert (
len(migrations) > 0
), f"no migration scripts found -- wrong migraion path for {__package__}"
), f"no migration scripts found -- wrong migration path for {__package__}"
migrations_to_apply = backend.to_apply(migrations)
backend.apply_migrations(migrations_to_apply)

0 comments on commit 3b6e4e3

Please sign in to comment.