Skip to content

Commit 7dd3dd9

Browse files
authored
Deprecate Filestore.uri_import (#1226)
* This function was accidentally left in; it does not work * The function to write a file located at URI to a filestore array is already correctly implemented by `Filestore.copy_from`
1 parent e912a0d commit 7dd3dd9

File tree

4 files changed

+38
-157
lines changed

4 files changed

+38
-157
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# In Progress
22

3+
## Improvements
4+
* `setup.py` revert back to retrieving core version by using `ctypes` by parsing `tiledb_version.h`; the tiledb shared object lib now returns back a full path [#1226](https://github.com/TileDB-Inc/TileDB-Py/pull/1226)
5+
36
## API Changes
47
* Addition of `in` operator for `QueryCondition` [#1214](https://github.com/TileDB-Inc/TileDB-Py/pull/1214)
58

9+
## Bug Fixes
10+
* Deprecate `Filestore.import_uri` in lieu of `Filestore.copy_from` [#1226](https://github.com/TileDB-Inc/TileDB-Py/pull/1226)
11+
612
# TileDB-Py 0.16.3 Release Notes
713

814
## Packaging Notes

tiledb/cc/filestore.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ class Filestore {
8383

8484
void init_filestore(py::module &m) {
8585
py::class_<Filestore>(m, "Filestore")
86-
.def_static("_schema_create", &Filestore::schema_create)
87-
.def_static("_uri_import", &Filestore::uri_import)
88-
.def_static("_uri_export", &Filestore::uri_export)
89-
.def_static("_buffer_import", &Filestore::buffer_import)
90-
.def_static("_buffer_export", &Filestore::buffer_export)
91-
.def_static("_size", &Filestore::size)
86+
.def_static("_schema_create", &Filestore::schema_create,
87+
py::keep_alive<1, 2>())
88+
.def_static("_uri_import", &Filestore::uri_import, py::keep_alive<1, 2>())
89+
.def_static("_uri_export", &Filestore::uri_export, py::keep_alive<1, 2>())
90+
.def_static("_buffer_import", &Filestore::buffer_import,
91+
py::keep_alive<1, 2>())
92+
.def_static("_buffer_export", &Filestore::buffer_export,
93+
py::keep_alive<1, 2>())
94+
.def_static("_size", &Filestore::size, py::keep_alive<1, 2>())
9295
.def_static("_mime_type_to_str", &Filestore::mime_type_to_str)
9396
.def_static("_mime_type_from_str", &Filestore::mime_type_from_str);
9497
;

tiledb/filestore.py

Lines changed: 7 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import ByteString, Optional, overload, TYPE_CHECKING
1+
from typing import ByteString, TYPE_CHECKING
2+
import warnings
23

34
import tiledb.cc as lt
45
from .ctx import default_ctx
@@ -138,79 +139,12 @@ def copy_to(filestore_array_uri: str, file_uri: str, ctx: "Ctx" = None) -> None:
138139

139140
lt.Filestore._uri_export(lt.Context(ctx, False), filestore_array_uri, file_uri)
140141

141-
def uri_import(self, uri: str, mime_type: str = "AUTODETECT") -> None:
142-
"""
143-
:param int offset: Byte position to begin reading. Defaults to beginning of filestore.
144-
:param int size: Total number of bytes to read. Defaults to -1 which reads the entire filestore.
145-
:rtype: bytes
146-
:return: Data from the Filestore Array
147-
148-
"""
149-
try:
150-
buffer = memoryview(buffer)
151-
except TypeError:
152-
raise TypeError(
153-
f"Unexpected buffer type: buffer must support buffer protocol"
154-
)
155-
156-
if not isinstance(mime_type, str):
157-
raise TypeError(
158-
f"Unexpected mime_type type '{type(mime_type)}': expected str"
159-
)
160-
161-
lt.Filestore._buffer_import(
162-
lt.Context(self._ctx, False),
163-
self._filestore_uri,
164-
offset,
165-
size,
142+
def uri_import(self, file_uri: str, mime_type: str = "AUTODETECT") -> None:
143+
warnings.warn(
144+
"Filestore.uri_import is deprecated; please use Filestore.copy_from",
145+
DeprecationWarning,
166146
)
167147

168-
def read(self, offset: int = 0, size: int = -1) -> bytes:
169-
"""
170-
:param int offset: Byte position to begin reading. Defaults to beginning of filestore.
171-
:param int size: Total number of bytes to read. Defaults to -1 which reads the entire filestore.
172-
:rtype: bytes
173-
:return: Data from the Filestore Array
174-
175-
"""
176-
if not isinstance(offset, int):
177-
raise TypeError(f"Unexpected offset type '{type(offset)}': expected int")
178-
179-
if not isinstance(size, int):
180-
raise TypeError(f"Unexpected size type '{type(size)}': expected int")
181-
182-
if size == -1:
183-
size = len(self)
184-
size = max(size - offset, 0)
185-
186-
return lt.Filestore._buffer_export(
187-
lt.Context(self._ctx, False),
188-
self._filestore_uri,
189-
offset,
190-
size,
191-
)
192-
193-
@staticmethod
194-
def copy_from(
195-
filestore_array_uri: str,
196-
file_uri: str,
197-
mime_type: str = "AUTODETECT",
198-
ctx: "Ctx" = None,
199-
) -> None:
200-
"""
201-
Copy data from a file to a Filestore Array.
202-
203-
:param str filestore_array_uri: The URI to the TileDB Fileshare Array
204-
:param str file_uri: URI of file to export
205-
:param str mime_type: MIME types are "AUTODETECT" (default), "image/tiff", "application/pdf"
206-
:param tiledb.Ctx ctx: A TileDB context
207-
208-
"""
209-
if not isinstance(filestore_array_uri, str):
210-
raise TypeError(
211-
f"Unexpected filestore_array_uri type '{type(filestore_array_uri)}': expected str"
212-
)
213-
214148
if not isinstance(file_uri, str):
215149
raise TypeError(
216150
f"Unexpected file_uri type '{type(file_uri)}': expected str"
@@ -221,91 +155,13 @@ def copy_from(
221155
f"Unexpected mime_type type '{type(mime_type)}': expected str"
222156
)
223157

224-
ctx = ctx or default_ctx()
225-
226158
lt.Filestore._uri_import(
227-
lt.Context(ctx, False),
228-
filestore_array_uri,
229-
file_uri,
230-
lt.Filestore._mime_type_from_str(mime_type),
231-
)
232-
233-
@staticmethod
234-
def copy_to(filestore_array_uri: str, file_uri: str, ctx: "Ctx" = None) -> None:
235-
"""
236-
Copy data from a Filestore Array to a file.
237-
238-
:param str filestore_array_uri: The URI to the TileDB Fileshare Array
239-
:param str file_uri: The URI to the TileDB Fileshare Array
240-
:param tiledb.Ctx ctx: A TileDB context
241-
242-
"""
243-
if not isinstance(filestore_array_uri, str):
244-
raise TypeError(
245-
f"Unexpected filestore_array_uri type '{type(filestore_array_uri)}': expected str"
246-
)
247-
248-
if not isinstance(file_uri, str):
249-
raise TypeError(
250-
f"Unexpected file_uri type '{type(file_uri)}': expected str"
251-
)
252-
253-
ctx = ctx or default_ctx()
254-
255-
lt.Filestore._uri_export(lt.Context(ctx, False), filestore_array_uri, file_uri)
256-
257-
def uri_import(self, uri: str, mime_type: str = "AUTODETECT") -> None:
258-
"""
259-
Import data from an object that supports the buffer protocol to a Filestore Array.
260-
261-
:param buffer ByteString: Data of type bytes, bytearray, memoryview, etc.
262-
:param str mime_type: MIME types are "AUTODETECT" (default), "image/tiff", "application/pdf"
263-
264-
"""
265-
try:
266-
buffer = memoryview(buffer)
267-
except TypeError:
268-
raise TypeError(
269-
f"Unexpected buffer type: buffer must support buffer protocol"
270-
)
271-
272-
if not isinstance(mime_type, str):
273-
raise TypeError(
274-
f"Unexpected mime_type type '{type(mime_type)}': expected str"
275-
)
276-
277-
lt.Filestore._buffer_import(
278159
lt.Context(self._ctx, False),
279160
self._filestore_uri,
280-
buffer,
161+
file_uri,
281162
lt.Filestore._mime_type_from_str(mime_type),
282163
)
283164

284-
def read(self, offset: int = 0, size: int = -1) -> bytes:
285-
"""
286-
:param int offset: Byte position to begin reading. Defaults to beginning of filestore.
287-
:param int size: Total number of bytes to read. Defaults to -1 which reads the entire filestore.
288-
:rtype: bytes
289-
:return: Data from the Filestore Array
290-
291-
"""
292-
if not isinstance(offset, int):
293-
raise TypeError(f"Unexpected offset type '{type(offset)}': expected int")
294-
295-
if not isinstance(size, int):
296-
raise TypeError(f"Unexpected size type '{type(size)}': expected int")
297-
298-
if size == -1:
299-
size = len(self)
300-
size = max(size - offset, 0)
301-
302-
return lt.Filestore._buffer_export(
303-
lt.Context(self._ctx, False),
304-
self._filestore_uri,
305-
offset,
306-
size,
307-
)
308-
309165
def __len__(self) -> int:
310166
"""
311167
:rtype: int

tiledb/tests/test_filestore.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ def test_uri(self, text_fname):
5252
assert data == fs.read(0, len(data))
5353
assert len(fs) == len(data)
5454

55+
def test_deprecated_uri(self, text_fname):
56+
path = self.path("test_uri")
57+
schema = tiledb.ArraySchema.from_file(text_fname)
58+
tiledb.Array.create(path, schema)
59+
60+
fs = tiledb.Filestore(path)
61+
with pytest.warns(
62+
DeprecationWarning, match="Filestore.uri_import is deprecated"
63+
):
64+
fs.uri_import(text_fname)
65+
66+
with open(text_fname, "rb") as text:
67+
data = text.read()
68+
assert data == fs.read(0, len(data))
69+
assert len(fs) == len(data)
70+
5571
def test_multiple_writes(self):
5672
path = self.path("test_buffer")
5773
schema = tiledb.ArraySchema.from_file()

0 commit comments

Comments
 (0)