Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: genetic dags #26

Merged
merged 22 commits into from
Sep 24, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: added path property for gcs path obj
Szymon Szyszkowski authored and project-defiant committed Sep 23, 2024
commit 37c15b4b162d6f3d828087c59c03383682b8ae14
9 changes: 8 additions & 1 deletion src/ot_orchestration/utils/path.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import multiprocessing
import re
from abc import abstractmethod
from dataclasses import dataclass
from functools import cached_property
from pathlib import Path
from typing import Any, Protocol, TypedDict
@@ -37,6 +38,7 @@ class PathSegments(TypedDict):

class ProtoPath(Protocol):
segments: PathSegments
path: str

@abstractmethod
def dump(self, data: Any) -> None:
@@ -127,6 +129,11 @@ def exists(self) -> bool:
"""
return self.native_path.exists()

@cached_property
def path(self) -> str:
"""Get path segment."""
return str(self.native_path)

@cached_property
def segments(self) -> PathSegments:
"""Get path segments.
@@ -176,7 +183,7 @@ def client(self) -> storage.Client:
adapter = HTTPAdapter(pool_connections=128, pool_maxsize=1024, max_retries=3)
client._http.mount("https://", adapter)
client._http._auth_request.session.mount("https://", adapter)
return
return client

@cached_property
def _match(self) -> re.Match:
15 changes: 15 additions & 0 deletions tests/test_io_manager.py
Original file line number Diff line number Diff line change
@@ -188,3 +188,18 @@ def test_bucket_property(self, gcs_path: str, bucket: str) -> None:
"""Test GCSPath object bucket property."""
gcs_path_obj = GCSPath(gcs_path)
assert gcs_path_obj.bucket == bucket

@pytest.mark.parametrize(
["gcs_path", "path"],
[
pytest.param(
"gs://bucket/prefix/filename",
"prefix/filename",
id="GCS path with bucket",
),
],
)
def test_path_property(self, gcs_path: str, path: str) -> None:
"""Test GCSPath object bucket property."""
gcs_path_obj = GCSPath(gcs_path)
assert gcs_path_obj.path == path