Skip to content

Commit

Permalink
Avoid using importlib.resources.files to keep compatibility with ol…
Browse files Browse the repository at this point in the history
…der Python
  • Loading branch information
althonos committed May 10, 2021
1 parent 27ee892 commit a7139aa
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions gecco/hmmer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Compatibility wrapper for HMMER binaries and output.
"""
import abc
import atexit
import collections
import configparser
import contextlib
Expand Down Expand Up @@ -152,11 +153,22 @@ def run(
def embedded_hmms() -> Iterator[HMM]:
"""Iterate over the embedded HMMs that are shipped with GECCO.
"""
for ini in importlib_resources.files(__name__).glob("*.ini"):
cfg = configparser.ConfigParser()
cfg.read(ini)
for filename in importlib_resources.contents(__name__):

if not filename.endswith(".ini"):
continue

ini_ctx = importlib_resources.path(__name__, filename)
ini_path = ini_ctx.__enter__()
atexit.register(ini_ctx.__exit__, None, None, None)

cfg = configparser.ConfigParser()
cfg.read(ini_path)
args = dict(cfg.items("hmm"))
args["size"] = int(args["size"])

yield HMM(path=os.fspath(ini.with_suffix(".h3m")), **args)
hmm_ctx = importlib_resources.path(__name__, filename.replace(".ini", ".h3m"))
hmm_path = hmm_ctx.__enter__()
atexit.register(hmm_ctx.__exit__, None, None, None)

yield HMM(path=os.fspath(hmm_path), **args)

0 comments on commit a7139aa

Please sign in to comment.