PuppetLibrary#

Import

from scenet import PuppetLibrary

Defined in

scenet.assets.contract (source)

Install

pip install scenet

Since

0.1

Stability

Public: follows semantic versioning. Below 1.0, a minor release may change it, and the CHANGELOG says how.

class scenet.assets.contract.PuppetLibrary[source]#

Bases: object

A set of puppets, by name: what a cast member’s reference is looked up in.

Built by hand from a mapping, read from a directory of *.puppet.yaml files, or the two shipped puppets from default_library. Every compile takes one as library=.

Example

>>> from scenet import PuppetLibrary, compile_source, default_library
>>> alice = default_library().get("alice")
>>> library = PuppetLibrary({"alice": alice})
>>> library.names()
('alice',)
>>> compile_source("cast: {a: {reference: alice}}", library=library).core.actors[
...     0
... ].reference
'alice'

See also

load_puppet, to read one puppet. PuppetSpec, what each puppet is.

__init__(puppets)[source]#

Wrap an already-loaded mapping of puppets.

Parameters:

puppets (dict[str, PuppetSpec]) – Puppet name to specification. Usually built by from_directory rather than passed in directly – but constructing one by hand is how you supply your own characters without touching the filesystem.

classmethod from_directory(directory)[source]#

Load every *.puppet.yaml in a directory.

Parameters:

directory (Path) – Directory to scan. Not searched recursively.

Return type:

Self

Returns:

A library containing every puppet found.

Raises:
  • MalformedAssetError – Two files declare the same puppet name, or one is not a well-formed puppet. Also a ValueError.

  • FileReadError – A file cannot be read.

Files are visited in sorted order so that a duplicate-name collision reports the same offender on every platform, whatever order the filesystem hands them back.

get(name)[source]#

Look up one puppet by name.

Parameters:

name (str) – The name a cast member’s reference field points at.

Return type:

PuppetSpec

Returns:

That puppet’s specification.

Raises:

UnknownPuppetError – No puppet by that name. The message lists what is available, because the usual cause is a typo.

names()[source]#

Every puppet name in this library, sorted.

Example

>>> from scenet import default_library
>>> default_library().names()
('alice', 'bob')
Return type:

tuple[str, ...]

with_puppets(puppets)[source]#

This library and more puppets, each under the reference that names it.

Parameters:

puppets (Mapping[str, PuppetSpec]) – Reference to puppet: a puppet file’s, by the path a cast member writes.

Return type:

PuppetLibrary

Returns:

A new library. This one is unchanged.