Skip to content

Commit

Permalink
Add extra
Browse files Browse the repository at this point in the history
  • Loading branch information
bolkedebruin committed Oct 27, 2023
1 parent 88b9216 commit 5099f45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 18 additions & 3 deletions airflow/io/store/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class ObjectStoragePath(os.PathLike):
sep: typing.ClassVar[str] = "/"
root_marker: typing.ClassVar[str] = "/"

_store: ObjectStore | None
_bucket: str
_key: str
_conn_id: str | None
_protocol: str
_hash: int | None

__slots__ = (
"_store",
"_bucket",
Expand All @@ -54,18 +61,26 @@ class ObjectStoragePath(os.PathLike):
"_hash",
)

def __init__(self, path, conn_id: str | None = None, store: ObjectStore | None = None):
def __init__(
self, path: str | ObjectStoragePath, conn_id: str | None = None, store: ObjectStore | None = None
):
self._conn_id = conn_id
self._store = store

self._hash = None

self._protocol, self._bucket, self._key = self.split_path(path)
if isinstance(path, ObjectStoragePath):
self._protocol = path._protocol
self._bucket = path._bucket
self._key = path._key
self._store = path._store
else:
self._protocol, self._bucket, self._key = self.split_path(path)

if store:
self._conn_id = store.conn_id
self._protocol = self._protocol if self._protocol else store.protocol
elif self._protocol:
elif self._protocol and not self._store:
self._store = attach(self._protocol, conn_id)

@classmethod
Expand Down
5 changes: 5 additions & 0 deletions tests/io/store/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def test_init_objectstoragepath(self):
assert path.key == "key/part1/part2"
assert path._protocol == "file"

path2 = ObjectStoragePath(path / "part3")
assert path2.bucket == "bucket"
assert path2.key == "key/part1/part2/part3"
assert path2._protocol == "file"

def test_read_write(self):
o = ObjectStoragePath(f"file:///tmp/{str(uuid.uuid4())}")

Expand Down

0 comments on commit 5099f45

Please sign in to comment.