PuppetLibrary#
Import |
|
Defined in |
|
Install |
|
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:
objectA set of puppets, by name: what a cast member’s
referenceis looked up in.Built by hand from a mapping, read from a directory of
*.puppet.yamlfiles, or the two shipped puppets fromdefault_library. Every compile takes one aslibrary=.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 byfrom_directoryrather 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.yamlin a directory.- Parameters:
directory (
Path) – Directory to scan. Not searched recursively.- Return type:
- 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’sreferencefield points at.- Return type:
- 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')
- 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:
- Returns:
A new library. This one is unchanged.