Skip to content

Commit 03983d7

Browse files
committed
Wrap FileIO, FileHandle, and VFS
1 parent 8bbcd2d commit 03983d7

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

tiledb/cc/context.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ void init_context(py::module &m) {
1818

1919
.def_property_readonly("config", &Context::config)
2020
.def("set_tag", &Context::set_tag)
21-
.def("get_stats", &Context::stats);
21+
.def("get_stats", &Context::stats)
22+
.def("is_supported_fs", &Context::is_supported_fs);
2223
}
2324

2425
void init_config(py::module &m) {

tiledb/cc/enum.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ void init_enums(py::module &m) {
6565
py::enum_<tiledb_vfs_mode_t>(m, "VFSMode") DVENUM(READ) DVENUM(WRITE)
6666
DVENUM(APPEND);
6767

68+
py::enum_<tiledb_filesystem_t>(m, "FileSystem") DENUM(S3) DENUM(AZURE)
69+
DENUM(GCS) DENUM(HDFS);
70+
6871
// test helpers to check enum name against typed value
6972
m.def("_enum_string", &tiledb::impl::type_to_str);
7073
m.def("_enum_string",

tiledb/cc/vfs.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ class FileHandle {
5858
tiledb_vfs_open(this->_ctx, vfs.ptr().get(), uri.c_str(), mode, &this->_fh);
5959
}
6060

61-
~FileHandle() { tiledb_vfs_close(this->_ctx, this->_fh); }
61+
~FileHandle() {
62+
if (!this->closed())
63+
this->close();
64+
}
65+
66+
void close() { tiledb_vfs_close(this->_ctx, this->_fh); }
6267

6368
py::bytes read(uint64_t offset, uint64_t nbytes) {
6469
py::array data = py::array(py::dtype::of<std::byte>(), nbytes);
@@ -93,6 +98,7 @@ void init_file_handle(py::module &m) {
9398

9499
.def_property_readonly("closed", &FileHandle::closed)
95100

101+
.def("close", &FileHandle::close)
96102
.def("read", &FileHandle::read)
97103
.def("write", &FileHandle::write)
98104
.def("flush", &FileHandle::flush);

tiledb/libtiledb.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from collections import OrderedDict
1414

1515
from .ctx import default_ctx
1616
from .filter import FilterList
17+
from .vfs import VFS
1718

1819
import tiledb.cc as lt
1920

@@ -3453,7 +3454,7 @@ cdef class Array(object):
34533454
if overwrite:
34543455
if object_type(uri) == "array":
34553456
if uri.startswith("file://") or "://" not in uri:
3456-
if lt.VFS().remove_dir(uri) != TILEDB_OK:
3457+
if VFS().remove_dir(uri) != TILEDB_OK:
34573458
_raise_ctx_err(ctx_ptr, rc)
34583459
else:
34593460
raise TypeError("Cannot overwrite non-local array.")

tiledb/tests/test_libtiledb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,7 +3725,9 @@ def test_write_read(self):
37253725
self.assertEqual(vfs.file_size(self.path("abc")), 3)
37263726

37273727
fio = vfs.open(self.path("abc"), "rb")
3728-
with pytest.warns(DeprecationWarning, match="Use `FileIO.read`"):
3728+
with pytest.warns(
3729+
DeprecationWarning, match="Use `FileIO.seek` and `FileIO.read`"
3730+
):
37293731
self.assertEqual(vfs.read(fio, 0, 3), buffer)
37303732
fio.close()
37313733

@@ -3740,7 +3742,7 @@ def test_write_read(self):
37403742
fio.close()
37413743

37423744
# read from file that does not exist
3743-
with self.assertRaises(tiledb.TileDBError):
3745+
with self.assertRaises(IOError):
37443746
vfs.open(self.path("do_not_exist"), "rb")
37453747

37463748
def test_io(self):

0 commit comments

Comments
 (0)