Pack charms with local Python package dependencies
Project description
charmcraftlocal
Pack charms with local Python package dependencies
Installation
Install pipx: https://pipx.pypa.io/stable/installation/
pipx install charmcraftlocal
Usage
At the moment, only charms that manage Python dependencies with Poetry are supported.
Example directory layout
common/
# Local Python package with shared code
pyproject.toml
common/
__init__.py
kubernetes/
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
machines/
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
Example common/pyproject.toml
[project]
name = "common"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
Step 1: Add local package to charm dependencies
Repeat this step for each charm that depends on the local package.
poetry add ../common --editable
Example pyproject.toml
[tool.poetry.dependencies]
common = {path = "../common", develop = true}
Step 2: Install charmcraftlocal in charmcraft.yaml
Install charmcraftlocal in the poetry-deps charmcraft.yaml part.
Example charmcraft.yaml
parts:
poetry-deps:
plugin: nil
override-build: |
# [...]
"$HOME/.local/bin/uv" tool install --no-python-downloads charmcraftlocal
To install with pipx instead of uv, use pipx install charmcraftlocal
Step 3: Call charmcraftlocal in charmcraft.yaml
Run charmcraftlocal update-lock before poetry export runs in the charmcraft.yaml part with plugin: poetry
Example charmcraft.yaml
parts:
# [...]
charm-poetry:
plugin: poetry
after:
- poetry-deps
override-build: |
# [...]
"$HOME/.local/bin/charmcraftlocal" update-lock -v
craftctl default
# [...]
Step 4: Pack charm
ccl pack
How it works
Currently, during charmcraft pack, charmcraft can only access files in the directory that contains charmcraft.yaml.
charmcraftlocal pack
- searches (the charm's) pyproject.toml for local Python dependencies,
- copies them to the charm directory,
- and calls
charmcraft pack
charmcraftlocal update-lock (called by charmcraft pack)
- searches (the charm's) pyproject.toml for local Python dependencies
- and calls Poetry to update pyproject.toml and poetry.lock to reference the copied package(s)
Why does charmcraftlocal need to be called in charmcraft.yaml?
In the first prototype of charmcraftlocal
- only
ccl packneeded to be called, ccl packcalled Poetry to update pyproject.toml and poetry.lock,- and
ccl update-lockdid not exist
The design was changed to maintain compatibility with tooling that expects
- one charm per git repository,
- charmcraft.yaml located at the root of the git repository,
- and
charmcraft packto successfully build the charm
To maintain compatibility with that tooling, the ccl mirror command (WIP) automates the creation and updates of "mirror" git repositories that meet the above requirements.
For example, for a git repository with this directory layout
common/
# Local Python package with shared code
pyproject.toml
common/
__init__.py
kubernetes/
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
machines/
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
ccl mirror can be used to create two "mirror" repositories—
one for kubernetes
common/
# Local Python package with shared code
pyproject.toml
common/
__init__.py
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
and one for machines
common/
# Local Python package with shared code
pyproject.toml
common/
__init__.py
charmcraft.yaml
pyproject.toml
poetry.lock
# [...]
git-filter-repo is used to create these "mirror" repositories. In order to preserve commit history while avoiding merge conflicts, pyproject.toml and poetry.lock must not be modified between the source repository and the "mirror" repositories.
Therefore, pyproject.toml and poetry.lock are modified at build time by calling ccl update-lock in charmcraft.yaml. (This approach enables the "mirror" repositories to be successfully built with charmcraft pack.)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file charmcraftlocal-0.2.0.tar.gz.
File metadata
- Download URL: charmcraftlocal-0.2.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e529e2cabbcc8cac4114fe96985611e686b4d7ffb9748ecdb13ba63d241f902
|
|
| MD5 |
286e32e297c87b3106512eafa4129138
|
|
| BLAKE2b-256 |
6280db173f0f40c079e4fca1b21083d96704dab80064fe8e8397647e411699e7
|
Provenance
The following attestation bundles were made for charmcraftlocal-0.2.0.tar.gz:
Publisher:
release.yaml on canonical/charmcraftlocal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charmcraftlocal-0.2.0.tar.gz -
Subject digest:
1e529e2cabbcc8cac4114fe96985611e686b4d7ffb9748ecdb13ba63d241f902 - Sigstore transparency entry: 434037365
- Sigstore integration time:
-
Permalink:
canonical/charmcraftlocal@28d65ec77a19463b46b28b8b3c0505976bb9df2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@28d65ec77a19463b46b28b8b3c0505976bb9df2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file charmcraftlocal-0.2.0-py3-none-any.whl.
File metadata
- Download URL: charmcraftlocal-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4f37a060822dff27a4d911a9ec6e8e648863f6a14030a1c7e9145fc92af0096
|
|
| MD5 |
bd7ed78d18168dff4b7e5e7a4f4dc88a
|
|
| BLAKE2b-256 |
04d5baa4f8b4f1f76533df369828f8e73c321ed946eafa4f886d42766105e59a
|
Provenance
The following attestation bundles were made for charmcraftlocal-0.2.0-py3-none-any.whl:
Publisher:
release.yaml on canonical/charmcraftlocal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charmcraftlocal-0.2.0-py3-none-any.whl -
Subject digest:
d4f37a060822dff27a4d911a9ec6e8e648863f6a14030a1c7e9145fc92af0096 - Sigstore transparency entry: 434037386
- Sigstore integration time:
-
Permalink:
canonical/charmcraftlocal@28d65ec77a19463b46b28b8b3c0505976bb9df2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@28d65ec77a19463b46b28b8b3c0505976bb9df2e -
Trigger Event:
push
-
Statement type: