Skip to main content

canonicalwebteam.launchpad

Classes for triggering builds of snaps and Ubuntu images through the Launchpad API.

Usage

Local development

For local development, it's best to test this module with one of our website projects like ubuntu.com. For more information, follow this guide (internal only).

SnapBuilder

from canonicalwebteam.launchpad import SnapBuilder

snap_builder = SnapBuilder(
    username="build.snapcraft.io",
    token=os.getenv("SNAP_BUILDER_TOKEN"),
    secret=os.getenv("SNAP_BUILDER_SECRET"),
)

snap_name = "new-test-snap"
git_repo = "https://github.com/build-staging-snapcraft-io/test1"
snap_builder.create_snap(snap_name, git_repo)

new_snap = snap_builder.get_snap_by_store_name("new-test-snap")

create_snap authorizes store uploads using a root macaroon (typically obtained from the store's package_upload ACL endpoint). If that macaroon carries a third-party (SSO) caveat, Launchpad needs the matching discharge_macaroon as well, otherwise it will accept the authorization but never actually be able to upload builds — leaving every build stuck as "Unscheduled" ("Won't release") with no error surfaced:

snap_builder.create_snap(
    snap_name, git_repo, macaroon, discharge_macaroon=discharge_macaroon
)

Snaps that were created before a discharge macaroon was available can be repaired without recreating them, using complete_snap_authorization:

snap_builder.complete_snap_authorization(
    lp_snap_name, macaroon, discharge_macaroon=discharge_macaroon
)

ImageBuilder

from canonicalwebteam.launchpad import ImageBuilder

image_builder = ImageBuilder(
    username="image.build",
    token=os.getenv("IMAGE_BUILDER_TOKEN"),
    secret=os.getenv("IMAGE_BUILDER_SECRET"),
)

image_builder.build_image(
    board="cm3", system="core16", snaps=["code", "toto"]
)

Test fixtures

Tests check calls against fixtures representing the Launchpad API. These fixtures are generated using vcrpy, based on real calls to the API when the test was first run.

To new tests that rely on new API responses, or if we need to regenerate existing fixtures because the API has changed, the secrets need to be provided to authenticate with the API as follows:

export SNAP_BUILDER_TOKEN={token}
export SNAP_BUILDER_SECRET={secret}
export IMAGE_BUILDER_TOKEN={token}
export IMAGE_BUILDER_SECRET={secret}

rm tests/cassettes/...  # Remove any fixtures you need to regenerate

./setup.py test  # Run tests again to regenerate fixtures

Metadata

Release files for canonicalwebteam.launchpad 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canonicalwebteam.launchpad 0.10.0
File Size Uploaded
canonicalwebteam_launchpad-0.10.0.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for canonicalwebteam.launchpad 0.10.0
File Interpreter ABI Platform
canonicalwebteam_launchpad-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / canonicalwebteam_launchpad-0.10.0.tar.gz

Download URL canonicalwebteam_launchpad-0.10.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7bf7ccee7265aaaedf9c04dea16b3f844b202b0a46ab3458855d1967f609b2cf
BLAKE2b-256 checksum
How to use checksums
6ca2745dad0fbe6444811bf1961be8ff6b41113774b7ecec15cac6c88d80de43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / canonicalwebteam_launchpad-0.10.0-py3-none-any.whl

Download URL canonicalwebteam_launchpad-0.10.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b807c3a02ef77940c4eeebebb4e0f75c29277ff09a1a95f111050da9572154db
BLAKE2b-256 checksum
How to use checksums
36b380ec7ddc4c702d6154f6259e328b7bea0182eaac1fe9f92fe49eae05cc2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page