quilt

Package()

In-memory representation of a package

manifest

Provides a generator of the dicts that make up the serialized package.

top_hash

Returns the top hash of the package.

Note that physical keys are not hashed because the package has the same semantics regardless of where the bytes come from.

Returns

A string that represents the top hash of the package

Package.__repr__(self, max_lines=20) {#Package.__repr__}

String representation of the Package.

Package.install(name, registry=None, top_hash=None, dest=None, dest_registry=None, *, path=None)

Installs a named package to the local registry and downloads its files.

Arguments

A package URI cannot be combined with registry, top_hash, or path. Its optional path uses the same selective-install behavior as path.

Package.resolve_hash(name, registry, hash_prefix) {#Package.resolve_hash}

Find a hash that starts with a given prefix.

Arguments

Package.browse(name, registry=None, top_hash=None)

Load a package into memory from a registry without making a local copy of the manifest.

Arguments

A package URI cannot be combined with registry or top_hash. If the URI selects a path, return that entry or subpackage instead of the full package.

Package.__contains__(self, logical_key) {#Package.__contains__}

Checks whether the package contains a specified logical_key.

Returns

True or False

Package.__getitem__(self, logical_key) {#Package.__getitem__}

Filters the package based on prefix, and returns either a new Package or a PackageEntry.

Arguments

Returns

PackageEntry if prefix matches a logical_key exactly otherwise Package

Package.fetch(self, dest=’./’)

Copy all descendants to dest. Descendants are written under their logical names relative to self.

Arguments

Returns

A new Package object with entries from self, but with physical keys pointing to files in dest.

Package.keys(self)

Returns logical keys in the package.

Package.walk(self)

Generator that traverses all entries in the package tree and returns tuples of (key, entry), with keys in alphabetical order.

Package.load(readable_file)

Loads a package from a readable file-like object.

Arguments

Returns

A new Package object

Raises

file not found json decode error invalid package exception

Package.set_dir(self, lkey, path=None, meta=None, update_policy=’incoming’, unversioned: bool = False) {#Package.set_dir}

Adds all files from path to the package.

Recursively enumerates every file in path, and adds them to the package according to their relative location to path.

Arguments

Returns

self

Raises

Package.get(self, logical_key)

Gets object from logical_key and returns its physical path. Equivalent to self[logical_key].get().

Arguments

Returns

Physical path as a string.

Raises

Package.readme(self)

Returns the README PackageEntry

The README is the entry with the logical key ‘README.md’ (case-sensitive). Will raise a QuiltException if no such entry exists.

Package.set_meta(self, meta) {#Package.set_meta}

Sets user metadata on this Package.

Package.build(self, name, registry=None, message=None, *, workflow=Ellipsis)

Serializes this package to a registry.

Arguments

Returns

The top hash as a string.

Package.dump(self, writable_file)

Serializes this package to a writable file-like object.

Arguments

Returns

None

Raises

fail to create file fail to finish write

Package.set(self, logical_key, entry=None, meta=None, serialization_location=None, serialization_format_opts=None, unversioned: bool = False)

Returns self with the object at logical_key set to entry.

Arguments

Returns

self

Package.delete(self, logical_key)

Returns self with logical_key removed.

Returns

self

Raises

Package.push(self, name, registry=None, dest=None, message=None, selector_fn=None, *, workflow=Ellipsis, force: bool = False, dedupe: bool = False)

Creates a new package, or a new revision of an existing package in a package registry in Amazon S3.

By default, any files not currently in the destination bucket are copied to the destination S3 bucket at a path matching logical key structure. Files in the destination bucket are not copied even if they are not located in in the location matching the logical key. After objects are copied, a new package manifest is package manifest is created that points to the objects in their new locations.

The optional parameter selector_fn allows callers to choose which files are copied to the destination bucket, and which retain their existing physical key. When using selector functions, it is important to always copy local files to S3, otherwise the resulting package will be inaccessible to users accessing it from Amazon S3.

The Package class includes two additional built-in selector functions:

If we have a package with entries:

And, we call pkg.push("user/pkg_name", registry="s3://bucket2"), the file referenced by entry_1 will be copied, while the file referenced by entry_2 will not. The resulting package will have the following entries:

Quilt3 Versions 6.3.1 and earlier copied all files to the destination path by default. To match this behavior in later versions, callers should use selector_fn=Package.selector_fn_copy_all.

Using the same initial package and push, but adding selector_fn=Package.selector_fn_copy_all will result in both files being copied to the destination path, producing the following package:

Note that push is careful to not push data unnecessarily. To illustrate, imagine you have a PackageEntry: pkg["entry_1"].physical_key = "/tmp/package_entry_1.json"

If that entry would be pushed to s3://bucket/prefix/entry_1.json, but s3://bucket/prefix/entry_1.json already contains the exact same bytes as ‘/tmp/package_entry_1.json’, quilt3 will not push the bytes to S3, no matter what selector_fn('entry_1', pkg["entry_1"]) returns.

By default, push will not overwrite an existing package if its top hash does not match the parent hash of the package being pushed. Use force=True to skip the check.

A successful push records the revision it published on the package it was called on, in addition to the package it returns. Either object can therefore push again – as the next revision at the same destination, or as the same revision to another registry holding the parent – without an intervening browse() and without force=True.

Arguments

Returns

A new package that points to the copied objects.

Package.rollback(name, registry, top_hash)

Set the “latest” version to the given hash.

Arguments

Package.diff(self, other_pkg)

Returns three lists – added, modified, deleted.

Added: present in other_pkg but not in self. Modified: present in both, but different. Deleted: present in self, but not other_pkg.

Arguments

Returns

added, modified, deleted (all lists of logical keys)

Package.map(self, f, include_directories=False)

Performs a user-specified operation on each entry in the package.

Arguments

Returns: list The list of results generated by the map.

Package.filter(self, f, include_directories=False)

Applies a user-specified operation to each entry in the package, removing results that evaluate to False from the output.

Arguments

Returns

A new package with entries that evaluated to False removed

Package.verify(self, src, extra_files_ok=False)

Check if the contents of the given directory matches the package manifest.

Arguments

Returns

True if the package matches the directory; False otherwise.

PackageEntry(physical_key, size, hash_obj, meta)

Represents an entry at a logical key inside a package.

__init__

Creates an entry.

Arguments

Returns

a PackageEntry

PackageEntry.as_dict(self) {#PackageEntry.as_dict}

Returns dict representation of entry.

PackageEntry.set_meta(self, meta) {#PackageEntry.set_meta}

Sets the user_meta for this PackageEntry.

PackageEntry.set(self, path=None, meta=None)

Returns self with the physical key set to path.

Arguments

Returns

self

PackageEntry.get(self)

Returns the physical key of this PackageEntry.

PackageEntry.get_cached_path(self) {#PackageEntry.get_cached_path}

Returns a locally cached physical key, if available.

PackageEntry.get_bytes(self, use_cache_if_available=True) {#PackageEntry.get_bytes}

Returns the bytes of the object this entry corresponds to. If ‘use_cache_if_available’=True, will first try to retrieve the bytes from cache.

PackageEntry.get_as_json(self, use_cache_if_available=True) {#PackageEntry.get_as_json}

Returns a JSON file as a dict. Assumes that the file is encoded using utf-8.

If ‘use_cache_if_available’=True, will first try to retrieve the object from cache.

PackageEntry.get_as_string(self, use_cache_if_available=True) {#PackageEntry.get_as_string}

Return the object as a string. Assumes that the file is encoded using utf-8.

If ‘use_cache_if_available’=True, will first try to retrieve the object from cache.

PackageEntry.deserialize(self, func=None, **format_opts)

Returns the object this entry corresponds to.

Arguments

Returns

The deserialized object from the logical_key

Raises

physical key failure hash verification fail when deserialization metadata is not present

PackageEntry.fetch(self, dest=None)

Gets objects from entry and saves them to dest.

Arguments

Returns

None

PackageEntry.__call__(self, func=None, **kwargs) {#PackageEntry.__call__}

Shorthand for self.deserialize()