Skip to content

Commit

Permalink
fix: update snap to build with uv
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Dec 8, 2024
1 parent 2e210fe commit ebbbd3c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ ignore-decorators = [ # Functions with these decorators don't have to have docs

[[tool.uv.index]]
name = "python-apt-wheels"
url = "https://people.canonical.com/~lengau/python-apt-pypi/"
url = "https://people.canonical.com/~lengau/python-apt-ubuntu-wheels/"

[tool.uv]
constraint-dependencies = [
Expand Down Expand Up @@ -399,6 +399,4 @@ dev = [
"pytest-mock>=3.14.0",
"pytest-subprocess>=1.5.2",
"responses>=0.25.3",
# Repeating the apt extra so dev environments on Linux always get python-apt.
"python-apt>=2.4.0;sys_platform=='linux'"
]
4 changes: 3 additions & 1 deletion snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
#!/bin/sh
'''exec' "$(dirname -- "$(realpath -- "$0")")"/../../bin/'python3' "$0" "$@"
' '''

"""Clean all related obsoleted and outdated LXD base images and instances.
Expand Down
4 changes: 3 additions & 1 deletion snap/hooks/remove
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
#!/bin/sh
'''exec' "$(dirname -- "$(realpath -- "$0")")"/../../bin/'python3' "$0" "$@"
' '''

"""Remove all related LXD images and instances when removing the snap."""

Expand Down
57 changes: 40 additions & 17 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ parts:
charmcraft:
after: [charmcraft-libs, libgit2]
source: .
plugin: python
python-requirements:
- requirements-jammy.txt
- requirements.txt
plugin: nil
build-environment:
# CFLAGS for Python 3.10 and libyaml. Allows cryptography and pyyaml to find
# the appropriate system libraries.
Expand All @@ -136,27 +133,53 @@ parts:
- PIP_NO_BINARY: ":all:"
- CRYPTOGRAPHY_OPENSSL_NO_LEGACY: "true"
- UV_FROZEN: "true"
- UV_PYTHON: /usr/bin/python3
- MAKEOPTS: -j$(nproc --all)
- UV_PYTHON_DOWNLOADS: never
- UV_COMPILE_BYTECODE: "true"
- CLICOLOR_FORCE: "true"
build-attributes:
- enable-patchelf
override-pull: |
craftctl default
# Need the full path for craftctl because we stage our own craftctl to the path.
/snap/snapcraft/current/libexec/snapcraft/craftctl default
# Ensure we don't have a dubious ownership error from git with a remote build.
git config --global --add safe.directory $CRAFT_PART_SRC
# set the version
version="$(python3 setup.py --version)"
craftctl set version="${version}"
[ -n "$(echo $version | grep "post")" ] && grade=devel || grade=stable
craftctl set grade="${grade}"
# Set up the rust compiler
rustup default 1.79
override-build: |
uv export --no-dev --no-emit-workspace --output-file $CRAFT_PART_SRC/requirements.txt
craftctl default
cp -v completion.bash ../install
sed -i -e '1 s|^#!/.*|#!/snap/charmcraft/current/bin/python -E|' $CRAFT_PART_INSTALL/bin/craftctl
organize:
bin/craftctl: libexec/charmcraft/craftctl
uv export --no-dev --output-file=requirements.txt
uv venv --relocatable $CRAFT_PART_INSTALL
uv pip install --python $CRAFT_PART_INSTALL/bin/python -r requirements-jammy.txt -r requirements.txt
uv pip install --python $CRAFT_PART_INSTALL/bin/python --link-mode copy "charmcraft @ $CRAFT_PART_BUILD"
cp -v completion.bash $CRAFT_PART_INSTALL
mkdir -p $CRAFT_PART_INSTALL/libexec/charmcraft
ln -s ../../bin/craftctl $CRAFT_PART_INSTALL/libexec/charmcraft/craftctl
version="$(uv --quiet run charmcraft --version | cut -d' ' -f2)"
/snap/snapcraft/current/libexec/snapcraft/craftctl set version="${version}"
[ -n "$(echo $version | grep "post")" ] && grade=devel || grade=stable
/snap/snapcraft/current/libexec/snapcraft/craftctl set grade="${grade}"
rm $CRAFT_PART_INSTALL/bin/python*
rm $CRAFT_PART_INSTALL/lib64
ln -s ../usr/bin/python3 $CRAFT_PART_INSTALL/bin/python3
ln -s python3 $CRAFT_PART_INSTALL/bin/python
stage:
- -bin/activate*
- -bin/chardetect
- -bin/craft-providers
- -bin/distro
- -bin/jsonschema
- -bin/deactivate*
- -bin/keyring
- -bin/normalizer
- -bin/pip*
- -bin/pydoc*
- -bin/snap-helpers
- -bin/tabulate
# organize:

Check warning on line 181 in snap/snapcraft.yaml

View workflow job for this annotation

GitHub Actions / lint / files

181:5 [comments-indentation] comment not indented like content
# bin/craftctl: libexec/charmcraft/craftctl

skopeo: # Copied from Rockcraft
plugin: nil
Expand Down
28 changes: 22 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ebbbd3c

Please sign in to comment.