Developer reference

Package / repository initialisation.

See online documentation at RTD.

class mold.Category(module: str, name: str, description: str)

Collection of tools to pick one out of during initialisation.

description: str
module: str
name: str
class mold.Domain(module: str, name: str, description: str)

Project domain.

Connects all relevant tools together.

add_tool(tool: mold.Tool)

Register a tool to this domain.

tools: List[mold.Tool]
class mold.Interface(module: str, name: str, description: str, provides: type, accepts: type, parents: List[mold.Interface] = <factory>, questions: List[mold.Question] = <factory>, post_dialog: Callable[[], None] = <factory>)

Tool interface that provides and accepts configuration, and provides dialog.

Parameters

post_dialog (Callable[[], None]) – this interface must provide the variables in “Provides” and may use the provided variables of dependencies

accepts: type
static get_namespace_dict(namespace) dict

Parse variables from a namespace, i.e. provides and accepts.

parents: List[mold.Interface]
post_dialog: Callable[[], None]
provides: type
questions: List[mold.Question]

Tool-agnostic way of representing hyperlinks.

pre_text: str = None
target: str
text: str
class mold.Question(id: str, prompt: str, prefill: bool = False)

Question dialog.

id: str
prefill: bool = False
prompt: str
response: str
class mold.Template(target_path: pathlib.Path, content: str)

Jinja2 template file.

content: str
target_path: pathlib.Path
class mold.Tool(module: str, name: str, description: str, depends: List[Union[mold.Tool, mold.Interface]], category: Optional[mold.Category] = None, templates: Callable[[], List[mold.Template]] = <factory>, provide_vars: Callable[[], None] = <factory>, accept_vars: Callable[[], None] = <factory>, handle_accept: Callable[[], None] = <factory>)

Tool implementation.

Parameters
  • provide_vars (Callable[[], None]) – this loader must provide the variables in “Provides”, it may also modify the variables in “Accepts” or the accepted variables of other loaders

  • accept_vars (Callable[[], None]) – this loader and other loaders may modify the accepted variables, this loader may modify the provided variables using the provided variables of other loaders that are depended on

  • handle_accept (Callable[[], None]) – this loader may modify the accepted variables

accept_vars: Callable[[], None]
category: mold.Category = None
depends: List[Union[mold.Tool, mold.Interface]]
handle_accept: Callable[[], None]
provide_vars: Callable[[], None]
templates: Callable[[], List[mold.Template]]
mold.templates_from_directory(init_file: str) Callable[[], List[mold.Template]]

Generate templates from a directory “templates” relative to path.

Creating plugins

Mold ships with a builtin configuration for creating plugins. Initialise a python-library and choose Mold plugin as the source. It contains example source code for creating each type of plugin.

$ mold python-library

Plugin hook

A hook for external modules to attach their domains to.

Provides the guaranteed configuration values:

  • project_name

  • project_slug

class mold.hook.Accepts

Global domain accepts variables.

class mold.hook.Provides

Global domain provides variables.

project_name: str = ''
project_slug: str = ''
mold.hook.add_domain(domain: mold.Domain)

Add domain to the pool of alternatives.

Documentation

Utilities for creating plugin documentation.

mold.doc.render_doc(import_location: str) str

Render documentation for any Mold component.

The component is imported and introspected to determine the appropriate documentation template, which is filled with the component’s attributes.

Parameters

import_location – dotted name leading to the component, e.g. mold.plugins.domains.python

mold.doc.render_docs(intro_text: str, domain_locations: Optional[List[str]] = None, tool_locations: Optional[List[str]] = None, category_locations: Optional[List[str]] = None, interface_locations: Optional[List[str]] = None) str

Render documentation for Mold components.

Components are documented with render_doc() and gathered by type to a single document whose main heading has a reference plugins.

Parameters
  • intro_text – text to include under the main header

  • domain_locations – domain import locations

  • tool_locations – tool import locations

  • category_locations – category import locations

  • interface_locations – interface import locations