Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions avrokit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
... writer.roll() # Create a new partition file
"""

from importlib.metadata import version

__version__ = version("avrokit")

from .url import URL, FileURL, parse_url, create_url_mapping, flatten_urls
from .io import (
Appendable,
Expand Down
8 changes: 5 additions & 3 deletions avrokit/url/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def size(self) -> int:
if not blob.exists():
return 0
blob.reload() # N.b. loads metadata including size
return blob.size
return blob.size if blob.size is not None else 0

@override
def open(self) -> IO[Any]:
Expand All @@ -119,11 +119,13 @@ def open(self) -> IO[Any]:
self._current_remote = blob
self._current_local = tmpfile
self._current_local_stream = self._current_local
# Download to file if r or "rb" mode
if "r" in self.mode:
# Download to file if r/rb mode, or if append mode (to preserve existing content on failure)
if "r" in self.mode or "a" in self.mode:
# N.b. always writes in binary mode
blob.download_to_file(tmpfile)
tmpfile.seek(0)
if "a" in self.mode:
tmpfile.seek(0, 2) # Seek to end for append mode
if "b" not in self.mode:
# So if the user wants to read text, we need to decode it
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
Expand Down
6 changes: 4 additions & 2 deletions avrokit/url/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ def open(self) -> IO[Any]:
self._current_client = client
self._current_local = tmpfile
self._current_local_stream = self._current_local
# Download to file if "r" or "rb" mode
if "r" in self.mode:
# Download to file if "r"/"rb" mode, or if append mode (to preserve existing content on failure)
if "r" in self.mode or "a" in self.mode:
# N.b. always writes in binary mode
client.download_fileobj(self.bucket, self.path, tmpfile)
tmpfile.seek(0)
if "a" in self.mode:
tmpfile.seek(0, 2) # Seek to end for append mode
if "b" not in self.mode:
# So if the user wants to read text, we need to decode it
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[tool.poetry]
name = "avrokit"
version = "0.0.2"
version = "0.0.3"
description = "Python utilities for working with Avro data files"
authors = ["Greg Brandt <brandt.greg@gmail.com>"]
license = "Apache-2.0"
Expand Down