Skip to content

Commit

Permalink
protect importlib usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed May 24, 2024
1 parent e22c28d commit e89b557
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies=[
"biocommons.seqrepo >= 0.6.5",
"bioutils >= 0.4.0,<1.0",
"configparser >= 3.3.0",
"importlib_resources",
"ipython",
"parsley",
"psycopg2",
Expand Down
7 changes: 5 additions & 2 deletions src/hgvs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import re
from configparser import ConfigParser, ExtendedInterpolation
from copy import copy
from importlib import resources
try:
from importlib.resources import files as resources_files
except ImportError:
from importlib_resources import files as resources_files

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -115,6 +118,6 @@ def _val_xform(v):


_default_config = Config()
_default_config.read_stream(resources.files(__package__) / "_data" / "defaults.ini")
_default_config.read_stream(resources_files(__package__) / "_data" / "defaults.ini")

global_config = copy(_default_config)
7 changes: 5 additions & 2 deletions tests/test_hgvs_grammar_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import re
import unittest
from sys import version_info
from importlib import resources
try:
from importlib.resources import files as resources_files
except ImportError:
from importlib_resources import files as resources_files

#
# Tests of the grammar
Expand Down Expand Up @@ -51,7 +54,7 @@ def test_parser_test_completeness(self):
"""ensure that all rules in grammar have tests"""

grammar_rule_re = re.compile(r"^(\w+)")
grammar_fn = resources.files("hgvs") / "_data" / "hgvs.pymeta"
grammar_fn = resources_files("hgvs") / "_data" / "hgvs.pymeta"
with open(grammar_fn, "r") as f:
grammar_rules = set(r.group(1) for r in filter(None, map(grammar_rule_re.match, f)))

Expand Down

0 comments on commit e89b557

Please sign in to comment.