Skip to content

Commit

Permalink
Fix build issues (#939)
Browse files Browse the repository at this point in the history
* Dummy comment

* Small refactoring to make lint happy

* Add space

* Remove space
  • Loading branch information
sfiligoi authored May 2, 2024
1 parent 7182747 commit 96cc1cb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions biom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ def biom_open(fp, permission='r'):
if permission not in ['r', 'w', 'U', 'rb', 'wb']:
raise OSError("Unknown mode: %s" % permission)

opener = functools.partial(io.open, encoding='utf-8')
mode = permission

# don't try to open an HDF5 file if H5PY is not installed, this can only
Expand All @@ -434,19 +433,20 @@ def biom_open(fp, permission='r'):
if os.path.getsize(fp) == 0:
raise ValueError("The file '%s' is empty and can't be parsed" % fp)

if mode in ['U', 'r', 'rb'] and h5py.is_hdf5(fp):
opener = h5py.File
mode = 'r' if permission == 'U' else permission
elif mode == 'w':
opener = h5py.File

if mode in ['U', 'r', 'rb'] and is_gzip(fp):
def opener(fp, mode): # noqa
return codecs.getreader('utf-8')(gzip_open(fp, mode))
mode = 'rb' if permission in ['U', 'r'] else permission
elif mode in ['w', 'wb'] and str(fp).endswith('.gz'):
def opener(fp, mode): # noqa
codecs.getwriter('utf-8')(gzip_open(fp, mode))
elif mode in ['U', 'r', 'rb'] and h5py.is_hdf5(fp):
opener = h5py.File
mode = 'r' if permission == 'U' else permission
elif mode == 'w':
opener = h5py.File
else:
opener = functools.partial(io.open, encoding='utf-8')

f = opener(fp, mode)
try:
Expand Down

0 comments on commit 96cc1cb

Please sign in to comment.