Skip to content

Commit

Permalink
Merge pull request h5py#1922 from sbacchio/master
Browse files Browse the repository at this point in the history
Except OSError for certain drivers when creating a file with "a"
  • Loading branch information
takluyver authored Jul 20, 2021
2 parents a6c6590 + 13d65b0 commit b578203
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -908,5 +908,10 @@
num_commits: 1
first_commit: 2021-04-12 10:48:16
github: mgorny
- name: Simone Bacchio
email: [email protected]
num_commits: 5
first_commit: 2021-07-07 15:52:51
github: sbacchio
- name: Filipe Laíns
email: [email protected]
13 changes: 12 additions & 1 deletion h5py/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,18 @@ def make_fid(name, mode, userblock_size, fapl, fcpl=None, swmr=False):
# existing one (ACC_EXCL)
try:
fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
except FileNotFoundError:
# Not all drivers raise FileNotFoundError (commented those that do not)
except FileNotFoundError if fapl.get_driver() in (
h5fd.SEC2,
# h5fd.STDIO,
# h5fd.CORE,
h5fd.FAMILY,
h5fd.WINDOWS,
# h5fd.MPIO,
# h5fd.MPIPOSIX,
h5fd.fileobj_driver,
h5fd.ROS3D if ros3 else -1,
) else OSError:
fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
else:
raise ValueError("Invalid mode; must be one of r, r+, w, w-, x, a")
Expand Down
26 changes: 26 additions & 0 deletions h5py/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def test_stdio(self):
self.assertEqual(fid.driver, 'stdio')
fid.close()

# Testing creation with append flag
fid = File(self.mktemp(), 'a', driver='stdio')
self.assertTrue(fid)
self.assertEqual(fid.driver, 'stdio')
fid.close()

@ut.skipUnless(os.name == 'posix', "Sec2 driver is supported on posix")
def test_sec2(self):
""" Sec2 driver is supported on posix """
Expand All @@ -248,6 +254,12 @@ def test_sec2(self):
self.assertEqual(fid.driver, 'sec2')
fid.close()

# Testing creation with append flag
fid = File(self.mktemp(), 'a', driver='sec2')
self.assertTrue(fid)
self.assertEqual(fid.driver, 'sec2')
fid.close()

def test_core(self):
""" Core driver is supported (no backing store) """
fname = self.mktemp()
Expand All @@ -257,6 +269,12 @@ def test_core(self):
fid.close()
self.assertFalse(os.path.exists(fname))

# Testing creation with append flag
fid = File(self.mktemp(), 'a', driver='core')
self.assertTrue(fid)
self.assertEqual(fid.driver, 'core')
fid.close()

def test_backing(self):
""" Core driver saves to file when backing store used """
fname = self.mktemp()
Expand Down Expand Up @@ -762,6 +780,14 @@ def test_mpio(self, mpi_file_name):
assert f
assert f.driver == 'mpio'

def test_mpio_append(self, mpi_file_name):
""" Testing creation of file with append """
from mpi4py import MPI

with File(mpi_file_name, 'a', driver='mpio', comm=MPI.COMM_WORLD) as f:
assert f
assert f.driver == 'mpio'

@pytest.mark.skipif(h5py.version.hdf5_version_tuple < (1, 8, 9),
reason="mpio atomic file operations were added in HDF5 1.8.9+")
def test_mpi_atomic(self, mpi_file_name):
Expand Down
4 changes: 4 additions & 0 deletions news/PR1922.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bug fixes
---------

* Fix bug introduced in version 3.3 that did not allow the creation of files using the flag "a" for certain drivers (e.g. mpiio, core and stdio)

0 comments on commit b578203

Please sign in to comment.