Adding parts processing to an application

A simple example

To add parts processing to an application, instantiate the LifecycleManager class passing the parts dictionary. Plan actions for the PRIME target step, and execute them:

import yaml
from craft_parts import LifecycleManager, Step

parts_yaml = """
parts:
  hello:
    plugin: autotools
    source: https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
    prime:
      - usr/local/bin/hello
      - usr/local/share/man/*
"""

parts = yaml.safe_load(parts_yaml)

lcm = LifecycleManager(parts, application_name="example", cache_dir=".")
actions = lcm.plan(Step.PRIME)
with lcm.action_executor() as aex:
    aex.execute(actions)

When executed, the lifecycle manager will download the tarball we specified, unpack it, run its configuration script, compile the source code, install the resulting artifacts, and extract only the files we want to deploy. The final result is a subtree containing the files we wanted to prime:

prime
prime/usr
prime/usr/local
prime/usr/local/bin
prime/usr/local/bin/hello
prime/usr/local/share
prime/usr/local/share/man
prime/usr/local/share/man/man1
prime/usr/local/share/man/man1/hello.1

Learning more