tostorchconnector 1.0.1__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tostorchconnector might be problematic. Click here for more details.
- {tostorchconnector-1.0.1/tostorchconnector.egg-info → tostorchconnector-1.0.3}/PKG-INFO +1 -1
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/pyproject.toml +1 -1
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/__init__.py +2 -1
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_object_reader.py +25 -7
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_object_writer.py +2 -3
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3/tostorchconnector.egg-info}/PKG-INFO +1 -1
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/SOURCES.txt +0 -1
- tostorchconnector-1.0.1/tostorchconnector/tos_error.py +0 -11
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/LICENSE +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/README.md +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/setup.cfg +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tests/test_tos_dataset.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tests/test_tosnativeclient.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_checkpoint.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_client.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_common.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_iterable_dataset.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_map_dataset.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_object_meta.py +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/dependency_links.txt +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/requires.txt +0 -0
- {tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/top_level.txt +0 -0
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "tostorchconnector"
|
|
8
|
-
version = "1.0.
|
|
8
|
+
version = "1.0.3"
|
|
9
9
|
description = "TOS connector integration for PyTorch"
|
|
10
10
|
authors = [{ name = "xiangshijian", email = "xiangshijian@bytedance.com" }]
|
|
11
11
|
requires-python = ">=3.8,<3.13"
|
|
@@ -3,7 +3,7 @@ from .tos_object_writer import TosObjectWriter
|
|
|
3
3
|
from .tos_iterable_dataset import TosIterableDataset
|
|
4
4
|
from .tos_map_dataset import TosMapDataset
|
|
5
5
|
from .tos_checkpoint import TosCheckpoint
|
|
6
|
-
from
|
|
6
|
+
from tosnativeclient import TosException, TosError
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
'TosObjectReader',
|
|
@@ -12,4 +12,5 @@ __all__ = [
|
|
|
12
12
|
'TosMapDataset',
|
|
13
13
|
'TosCheckpoint',
|
|
14
14
|
'TosError',
|
|
15
|
+
'TosException',
|
|
15
16
|
]
|
|
@@ -2,7 +2,7 @@ import io
|
|
|
2
2
|
import logging
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from os import SEEK_SET, SEEK_CUR, SEEK_END
|
|
5
|
-
from typing import Optional, Callable,
|
|
5
|
+
from typing import Optional, Callable, Any
|
|
6
6
|
|
|
7
7
|
from tos.models2 import GetObjectOutput
|
|
8
8
|
from tosnativeclient.tosnativeclient import ReadStream
|
|
@@ -16,14 +16,14 @@ class TosObjectReader(io.BufferedIOBase):
|
|
|
16
16
|
|
|
17
17
|
def __init__(self, bucket: str, key: str,
|
|
18
18
|
get_object_meta: Optional[Callable[[], TosObjectMeta]],
|
|
19
|
-
get_object_stream: Callable[[str, int],
|
|
19
|
+
get_object_stream: Callable[[str, int], Any]):
|
|
20
20
|
if not bucket:
|
|
21
21
|
raise ValueError('bucket is empty')
|
|
22
22
|
self._bucket = bucket
|
|
23
23
|
self._key = key
|
|
24
24
|
self._get_object_meta = get_object_meta
|
|
25
25
|
self._get_object_stream = get_object_stream
|
|
26
|
-
self._object_stream: Optional[
|
|
26
|
+
self._object_stream: Optional[Any] = None
|
|
27
27
|
self._object_stream_offset = 0
|
|
28
28
|
self._total_size: Optional[int] = None
|
|
29
29
|
self._read_offset = 0
|
|
@@ -37,6 +37,19 @@ class TosObjectReader(io.BufferedIOBase):
|
|
|
37
37
|
def key(self) -> str:
|
|
38
38
|
return self._key
|
|
39
39
|
|
|
40
|
+
def __enter__(self):
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
44
|
+
if exc_type is not None:
|
|
45
|
+
try:
|
|
46
|
+
log.info(f'Exception occurred before closing stream: {exc_type.__name__}: {exc_val}')
|
|
47
|
+
except:
|
|
48
|
+
pass
|
|
49
|
+
else:
|
|
50
|
+
if self._object_stream is not None:
|
|
51
|
+
self._object_stream.close()
|
|
52
|
+
|
|
40
53
|
def read(self, size: Optional[int] = None) -> Optional[bytes]:
|
|
41
54
|
if self._is_read_to_end():
|
|
42
55
|
return b''
|
|
@@ -52,12 +65,15 @@ class TosObjectReader(io.BufferedIOBase):
|
|
|
52
65
|
while 1:
|
|
53
66
|
chunk = self._object_stream.read(self._object_stream_offset, chunk_size)
|
|
54
67
|
if not chunk:
|
|
68
|
+
self._object_stream.close()
|
|
55
69
|
break
|
|
56
70
|
self._object_stream_offset += len(chunk)
|
|
57
71
|
self._buffer.write(chunk)
|
|
58
|
-
|
|
72
|
+
except:
|
|
59
73
|
self._object_stream.close()
|
|
60
|
-
|
|
74
|
+
raise
|
|
75
|
+
|
|
76
|
+
elif isinstance(self._object_stream, GetObjectOutput):
|
|
61
77
|
for chunk in self._object_stream:
|
|
62
78
|
self._buffer.write(chunk)
|
|
63
79
|
|
|
@@ -149,13 +165,15 @@ class TosObjectReader(io.BufferedIOBase):
|
|
|
149
165
|
while offset > size:
|
|
150
166
|
chunk = self._object_stream.read(self._object_stream_offset, chunk_size)
|
|
151
167
|
if not chunk:
|
|
168
|
+
self._object_stream.close()
|
|
152
169
|
break
|
|
153
170
|
size += self._buffer.write(chunk)
|
|
154
171
|
self._object_stream_offset += len(chunk)
|
|
155
172
|
self._total_size = self._buffer.tell()
|
|
156
|
-
|
|
173
|
+
except:
|
|
157
174
|
self._object_stream.close()
|
|
158
|
-
|
|
175
|
+
raise
|
|
176
|
+
elif isinstance(self._object_stream, GetObjectOutput):
|
|
159
177
|
try:
|
|
160
178
|
while offset > size:
|
|
161
179
|
size += self._buffer.write(next(self._object_stream))
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import io
|
|
2
2
|
import logging
|
|
3
3
|
import threading
|
|
4
|
-
from typing import Callable,
|
|
4
|
+
from typing import Callable, Any
|
|
5
5
|
|
|
6
6
|
from tos.models2 import PutObjectOutput
|
|
7
|
-
from tosnativeclient.tosnativeclient import WriteStream
|
|
8
7
|
|
|
9
8
|
log = logging.getLogger(__name__)
|
|
10
9
|
|
|
@@ -24,7 +23,7 @@ class PutObjectStream(object):
|
|
|
24
23
|
|
|
25
24
|
class TosObjectWriter(io.BufferedIOBase):
|
|
26
25
|
|
|
27
|
-
def __init__(self, bucket: str, key: str, put_object_stream:
|
|
26
|
+
def __init__(self, bucket: str, key: str, put_object_stream: Any):
|
|
28
27
|
if not bucket:
|
|
29
28
|
raise ValueError('bucket is empty')
|
|
30
29
|
self._bucket = bucket
|
|
@@ -7,7 +7,6 @@ tostorchconnector/__init__.py
|
|
|
7
7
|
tostorchconnector/tos_checkpoint.py
|
|
8
8
|
tostorchconnector/tos_client.py
|
|
9
9
|
tostorchconnector/tos_common.py
|
|
10
|
-
tostorchconnector/tos_error.py
|
|
11
10
|
tostorchconnector/tos_iterable_dataset.py
|
|
12
11
|
tostorchconnector/tos_map_dataset.py
|
|
13
12
|
tostorchconnector/tos_object_meta.py
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class TosError(Exception):
|
|
5
|
-
def __init__(self, message: str, status_code: Optional[int] = None, ec: Optional[str] = None,
|
|
6
|
-
request_id: Optional[str] = None):
|
|
7
|
-
super().__init__(message)
|
|
8
|
-
self.message = message
|
|
9
|
-
self.status_code = status_code
|
|
10
|
-
self.ec = ec
|
|
11
|
-
self.request_id = request_id
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector/tos_iterable_dataset.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{tostorchconnector-1.0.1 → tostorchconnector-1.0.3}/tostorchconnector.egg-info/top_level.txt
RENAMED
|
File without changes
|