Skip to content

Commit

Permalink
Merge pull request #1839 from takluyver/deprecate-default-file-mode-2
Browse files Browse the repository at this point in the history
Deprecate setting default_file_mode, only allow setting to 'r'
  • Loading branch information
tacaswell committed Jun 18, 2021
2 parents 1340914 + 95ce39f commit c731c3d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
4 changes: 1 addition & 3 deletions h5py/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def swmr_mode(self, value):
else:
raise RuntimeError('SWMR support is not available in HDF5 version {}.{}.{}.'.format(*hdf5_version))

def __init__(self, name, mode=None, driver=None,
def __init__(self, name, mode='r', driver=None,
libver=None, userblock_size=None, swmr=False,
rdcc_nslots=None, rdcc_nbytes=None, rdcc_w0=None,
track_order=None, fs_strategy=None, fs_persist=False, fs_threshold=1,
Expand Down Expand Up @@ -428,8 +428,6 @@ def __init__(self, name, mode=None, driver=None,

if track_order is None:
track_order = h5.get_config().track_order
if mode is None:
mode = h5.get_config().default_file_mode # default: 'r'

if fs_strategy and mode not in ('w', 'w-', 'x'):
raise ValueError("Unable to set file space strategy of an existing file")
Expand Down
19 changes: 12 additions & 7 deletions h5py/h5.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,18 @@ cdef class H5PYConfig:
return self._default_file_mode

def __set__(self, val):
if val in {'r', 'r+', 'x', 'w-', 'w', 'a'}:
if val != 'r':
warn("Using default_file_mode other than 'r' is deprecated. "
"Pass the mode to h5py.File() instead.",
category=H5pyDeprecationWarning,
)
self._default_file_mode = val
if val == 'r':
warn(
"Setting h5py.default_file_mode is deprecated. "
"'r' (read-only) is the default from h5py 3.0.",
category=H5pyDeprecationWarning,
)
elif val in {'r+', 'x', 'w-', 'w', 'a'}:
raise ValueError(
"Using default_file_mode other than 'r' is no longer "
"supported. Pass the mode to h5py.File() instead."

)
else:
raise ValueError("Invalid mode; must be one of r, r+, w, w-, x, a")

Expand Down
32 changes: 32 additions & 0 deletions news/deprecate-default-file-mode-2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
New features
------------

* <news item>

Deprecations
------------

* The ``default_file_mode`` config option is deprecated, and setting it to
values other than 'r' (for read-only mode) is no longer allowed. Pass the
mode when creating a :class:`.File` object instead of setting a global
default.

Exposing HDF5 functions
-----------------------

* <news item>

Bug fixes
---------

* <news item>

Building h5py
-------------

* <news item>

Development
-----------

* <news item>

0 comments on commit c731c3d

Please sign in to comment.