Skip to content

Commit

Permalink
Merge pull request #126 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
ENH: suppress verbose warnings from h5py
  • Loading branch information
GavinHuttley committed Jun 27, 2024
2 parents b70b7fe + 3158ff7 commit 10cbda3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/ensembl_lite/_db_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import dataclasses
import os
import sqlite3

from ensembl_lite._util import PathType, SerialisableMixin
Expand Down Expand Up @@ -147,16 +148,22 @@ def __setstate__(self, state):
obj._file = None

def __del__(self):
with contextlib.suppress(ValueError, AttributeError):
self._file.flush()

with contextlib.suppress(AttributeError):
self._file.close()

self._is_open = False
self.close()

def close(self):
if self._is_open:
self._file.flush()
self._file.close()
"""closes the hdf5 file"""
# hdf5 dumps content to stdout if resource already closed, so
# we trap that here, and capture expected exceptions raised in the process
with open(os.devnull, "w") as devnull:
with (
contextlib.redirect_stderr(devnull),
contextlib.redirect_stdout(devnull),
):
with contextlib.suppress(ValueError, AttributeError):
if self._is_open:
self._file.flush()

with contextlib.suppress(AttributeError):
self._file.close()

self._is_open = False
2 changes: 2 additions & 0 deletions src/ensembl_lite/_genomedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ def get_gene_table_for_species(
"score",
"strand",
"phase",
"symbol",
"description",
)
rows = []
for i, record in enumerate(annot_db.get_records_matching(biotype="gene")):
Expand Down

0 comments on commit 10cbda3

Please sign in to comment.