Skip to content

Commit

Permalink
Basic documentation for ArchiveOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
mih committed Jun 10, 2023
1 parent 8db32de commit bf6931b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions datalad_next/archive_operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class ArchiveOperations(ABC):
"""
"""Base class for handlers of particular archive formats and access methods
"""
def __init__(self, location: Any, *, cfg: ConfigManager | None = None):
"""
Expand All @@ -46,33 +46,48 @@ def __str__(self) -> str:

@property
def cfg(self) -> ConfigManager:
"""ConfigManager given to the constructor or the session default"""
if self._cfg is None:
self._cfg = datalad.cfg
return self._cfg

def __enter__(self):
"""Default implementation that does nothing in particular"""
return self

def __exit__(self, exc_type, exc_value, traceback):
"""Default implementation that only calls ``.close()``"""
self.close()
# we have no desired to suppress exception, indicate standard
# we have no desire to suppress an exception, indicate standard
# handling by not returning True
return

@contextmanager
@abstractmethod
def open(self, item: Any) -> IO:
"""
"""Get a file-like for an archive item/member
Parameters
----------
item:
Any identifier for an archive/item supported by a particular handler
"""
raise NotImplementedError

def close(self) -> None:
"""Default implementation for closing a archive handler
This implementation does nothing.
"""
pass

@abstractmethod
def __contains__(self, item: Any) -> bool:
"""Returns whether the archive contains an item matching an identifier
"""
raise NotImplementedError

@abstractmethod
def __iter__(self) -> Generator[FileSystemItem, None, None]:
"""Returns an iterator yielding archive items"""
raise NotImplementedError

0 comments on commit bf6931b

Please sign in to comment.