Skip to content

Commit a8a86fb

Browse files
authored
Refactor zipfile opening (#480)
1 parent 016770e commit a8a86fb

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

src/pyobo/struct/obo/reader.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from curies.preprocessing import BlocklistError
1919
from curies.vocabulary import SynonymScope
2020
from more_itertools import pairwise
21-
from pystow.utils import safe_open
21+
from pystow.utils import open_zipfile, safe_open
2222
from tqdm.auto import tqdm
2323

2424
from .reader_utils import (
@@ -78,16 +78,9 @@ def from_obo_path(
7878
"""Get the OBO graph from a path."""
7979
path = Path(path).expanduser().resolve()
8080
if path.suffix.endswith(".zip"):
81-
import io
82-
import zipfile
83-
8481
logger.info("[%s] parsing zipped OBO with obonet from %s", prefix or "<unknown>", path)
85-
with zipfile.ZipFile(path) as zf:
86-
with zf.open(path.name.removesuffix(".zip"), "r") as file:
87-
content = file.read().decode("utf-8")
88-
graph = _read_obo(
89-
io.StringIO(content), prefix, ignore_obsolete=ignore_obsolete, use_tqdm=use_tqdm
90-
)
82+
with open_zipfile(path, path.name.removesuffix(".zip")) as file:
83+
graph = _read_obo(file, prefix, ignore_obsolete=ignore_obsolete, use_tqdm=use_tqdm)
9184
else:
9285
logger.info("[%s] parsing OBO with obonet from %s", prefix or "<unknown>", path)
9386
with safe_open(path, operation="read") as file:

0 commit comments

Comments
 (0)