Skip to content
Open
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
3 changes: 3 additions & 0 deletions icechunk-python/python/icechunk/_icechunk_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ class ManifestFileInfo:
...

class PyRepository:
def _repr_html_(self) -> str: ...
@classmethod
def create(
cls,
Expand Down Expand Up @@ -1818,6 +1819,7 @@ class PyRepository:
def spec_version(self) -> int: ...

class PySession:
def _repr_html_(self) -> str: ...
@classmethod
def from_bytes(cls, data: bytes) -> PySession: ...
def __eq__(self, value: object) -> bool: ...
Expand Down Expand Up @@ -1889,6 +1891,7 @@ class PySession:
async def rebase_async(self, solver: ConflictSolver) -> None: ...

class PyStore:
def _repr_html_(self) -> str: ...
@classmethod
def from_bytes(cls, data: bytes) -> PyStore: ...
def __eq__(self, value: object) -> bool: ...
Expand Down
9 changes: 9 additions & 0 deletions icechunk-python/python/icechunk/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class Repository:
def __init__(self, repository: PyRepository):
self._repository = repository

def __repr__(self) -> str:
return repr(self._repository)

def __str__(self) -> str:
return str(self._repository)

def _repr_html_(self) -> str:
return self._repository._repr_html_()

@classmethod
def create(
cls,
Expand Down
9 changes: 9 additions & 0 deletions icechunk-python/python/icechunk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def __init__(self, session: PySession):
self._session = session
self._allow_changes = False

def __repr__(self) -> str:
return repr(self._session)

def __str__(self) -> str:
return str(self._session)

def _repr_html_(self) -> str:
return self._session._repr_html_()

def __eq__(self, value: object) -> bool:
if not isinstance(value, Session):
return False
Expand Down
9 changes: 9 additions & 0 deletions icechunk-python/python/icechunk/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def __eq__(self, value: object) -> bool:
return False
return self._store == value._store

def __repr__(self) -> str:
return repr(self._store)

def __str__(self) -> str:
return str(self._store)

def _repr_html_(self) -> str:
return self._store._repr_html_()

def __getstate__(self) -> object:
# for read_only sessions we allow pickling, this allows distributed reads without forking
writable = not self.session.read_only
Expand Down
28 changes: 23 additions & 5 deletions icechunk-python/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
sync::Arc,
};

use icechunk::display::{dataclass_html_repr, dataclass_repr, dataclass_str};
use itertools::Itertools;

use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -214,11 +215,13 @@ impl From<SnapshotInfo> for PySnapshotInfo {
#[pymethods]
impl PyManifestFileInfo {
pub(crate) fn __repr__(&self) -> String {
format!(
r#"ManifestFileInfo(id="{id}", size_bytes={size}, num_chunk_refs={chunks})"#,
id = self.id,
size = self.size_bytes,
chunks = self.num_chunk_refs,
dataclass_repr(
"ManifestFileInfo",
&[
("id", format!("\"{}\"", self.id)),
("size_bytes", self.size_bytes.to_string()),
("num_chunk_refs", self.num_chunk_refs.to_string()),
],
)
}
}
Expand Down Expand Up @@ -805,6 +808,21 @@ impl PyRepository {
/// Most functions in this class call `Runtime.block_on` so they need to `detach` so other
/// python threads can make progress in the case of an actual block
impl PyRepository {
pub(crate) fn __repr__(&self) -> String {
let storage_repr = format!("{}", self.0.blocking_read().storage());
dataclass_repr("Repository", &[("storage", storage_repr)])
}

pub(crate) fn __str__(&self) -> String {
let storage_str = format!("{}", self.0.blocking_read().storage());
dataclass_str("Repository", &[("storage", storage_str)])
}

pub(crate) fn _repr_html_(&self) -> String {
let storage_str = format!("{}", self.0.blocking_read().storage());
dataclass_html_repr("Repository", &[("storage", storage_str)])
}

#[classmethod]
#[pyo3(signature = (storage, *, config = None, authorize_virtual_chunk_access = None, spec_version = None))]
fn create(
Expand Down
61 changes: 61 additions & 0 deletions icechunk-python/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use async_stream::try_stream;
use futures::{StreamExt, TryStreamExt};
use icechunk::{
Store,
display::{dataclass_html_repr, dataclass_repr, dataclass_str},
format::{ChunkIndices, Path},
session::{Session, SessionErrorKind},
store::{StoreError, StoreErrorKind},
Expand Down Expand Up @@ -31,6 +32,66 @@ pub struct PySession(pub Arc<RwLock<Session>>);
/// Most functions in this class block, so they need to `detach` so other
/// python threads can make progress
impl PySession {
pub(crate) fn __repr__(&self) -> String {
let session = self.0.blocking_read();
let branch_repr = match session.branch() {
Some(b) => format!("\"{}\"", b),
None => "None".to_string(),
};
dataclass_repr(
"Session",
&[
("read_only", session.read_only().to_string()),
("snapshot_id", format!("\"{}\"", session.snapshot_id())),
("branch", branch_repr),
(
"has_uncommitted_changes",
session.has_uncommitted_changes().to_string(),
),
],
)
}

pub(crate) fn __str__(&self) -> String {
let session = self.0.blocking_read();
let branch_str = match session.branch() {
Some(b) => b.to_string(),
None => "None".to_string(),
};
dataclass_str(
"Session",
&[
("read_only", session.read_only().to_string()),
("snapshot_id", session.snapshot_id().to_string()),
("branch", branch_str),
(
"has_uncommitted_changes",
session.has_uncommitted_changes().to_string(),
),
],
)
}

pub(crate) fn _repr_html_(&self) -> String {
let session = self.0.blocking_read();
let branch_str = match session.branch() {
Some(b) => b.to_string(),
None => "None".to_string(),
};
dataclass_html_repr(
"Session",
&[
("read_only", session.read_only().to_string()),
("snapshot_id", session.snapshot_id().to_string()),
("branch", branch_str),
(
"has_uncommitted_changes",
session.has_uncommitted_changes().to_string(),
),
],
)
}

#[classmethod]
fn from_bytes(
_cls: Bound<'_, PyType>,
Expand Down
52 changes: 52 additions & 0 deletions icechunk-python/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::Utc;
use futures::{StreamExt, TryStreamExt};
use icechunk::{
Store,
display::{dataclass_html_repr, dataclass_repr, dataclass_str},
format::{
ChunkIndices, ChunkLength, ChunkOffset, Path,
manifest::{Checksum, SecondsSinceEpoch, VirtualChunkLocation, VirtualChunkRef},
Expand Down Expand Up @@ -125,6 +126,57 @@ impl PyStore {
Arc::ptr_eq(&self.0.session(), &other.0.session())
}

pub(crate) fn __repr__(&self) -> String {
let session = self.0.session();
let session_guard = session.blocking_read();
let branch_repr = match session_guard.branch() {
Some(b) => format!("\"{}\"", b),
None => "None".to_string(),
};
dataclass_repr(
"IcechunkStore",
&[
("read_only", session_guard.read_only().to_string()),
("snapshot_id", format!("\"{}\"", session_guard.snapshot_id())),
("branch", branch_repr),
],
)
}

pub(crate) fn __str__(&self) -> String {
let session = self.0.session();
let session_guard = session.blocking_read();
let branch_str = match session_guard.branch() {
Some(b) => b.to_string(),
None => "None".to_string(),
};
dataclass_str(
"IcechunkStore",
&[
("read_only", session_guard.read_only().to_string()),
("snapshot_id", session_guard.snapshot_id().to_string()),
("branch", branch_str),
],
)
}

pub(crate) fn _repr_html_(&self) -> String {
let session = self.0.session();
let session_guard = session.blocking_read();
let branch_str = match session_guard.branch() {
Some(b) => b.to_string(),
None => "None".to_string(),
};
dataclass_html_repr(
"IcechunkStore",
&[
("read_only", session_guard.read_only().to_string()),
("snapshot_id", session_guard.snapshot_id().to_string()),
("branch", branch_str),
],
)
}

#[getter]
fn read_only(&self, py: Python<'_>) -> PyIcechunkStoreResult<bool> {
// This is blocking function, we need to release the Gil
Expand Down
Loading