File snapshots

class hitsave.DirectorySnapshot(original_path: Path, relpath: Optional[Path], files: List[FileSnapshot], digest: str)

Similar to FileSnapshot, but snaps an entire directory.

digest: str

All files (including files in subdirectories),

original_path: Path

Path on users machine when the snapshot was taken.

relpath: Optional[Path]

Path relative to the workspace directory of the code that snapshotted this directory.

If it is none, then the snapshot was not taken on a directory that is in the workspace.

restore(workspace_dir=None, overwrite=True) Path

Restores the snapshotted directory. Returns the path of the directory that was restored.

restore_at(path: Path, overwrite=True) Path

Restores the directory at the given path. Returns the path to the root of the snapshotted directory. (which is the same as the path argument).

restore_safe() Path

Restores the directory to a location in hitsave’s cache directory (where we know that there is no chance of overwriting existing files).

class hitsave.FileSnapshot(relpath: Optional[Path], name: str, digest: str, time: datetime, content_length: int)

This represents the state of a file on the host machine at a particular point in time. Saved methods can return these to make it clear that a function’s result is stored in a file. You can then read this file directly.

content_length: int

Number of bytes of the file.

digest: str

BLAKE3 hash of the file

download()

Download the file from the cloud to the local file cache.

property has_local_cache

Returns true if the file has already been cached.

name: str

The name of the file.

open() IO[bytes]

Open the snapshot in read mode. (writing to a snapshot is not allowed.)

relpath: Optional[Path]

original path on host machine, relative to the workspace directory.

If it is None, then the file was snapshotted outside of the workspace directory.

restore(overwrite: Optional[bool] = None, project_path=None) Path

Write the snapshot back to its original location (given by relpath). Returns the absolute path of the file that was restored.

restore_at(path: Path, overwrite: Optional[bool] = None) Path

Restore the file at the given path. Returns the path of the restored file. If the given path is a directory, the file will be stored in the directory with the file’s given basename. Otherwise the file will be saved at the exact path. If path has a different extension to the snapshot’s path extension then we emit a value-error, because it’s likely there was a mistake.

restore_safe() Path

Downloads the file snapshot and returns a path to the snapshot. Guaranteed not to overwrite anything. rename to get_path

classmethod snap(path: Union[Path, str], workspace_dir=None)

Make a snapshot of the file at the given path.

The path is stored relative to your workspace directory (either the location of your pyproject.toml or git root).

property suffix

The suffix extension of the file. Eg hello.txt has the suffix .txt.

time: datetime

Time at which the file was snap-shotted.

hitsave.restore(digest: str) Path

Pull and restore the blob with the given digest.

Raises:

FileNotFoundError: if not a known digest.