Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate setting default_file_mode, only allow setting to 'r' #1839

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions h5py/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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 @@ -424,8 +424,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>