Skip to content

Commit

Permalink
chore: add sitecustomize for plugin loading (#5283)
Browse files Browse the repository at this point in the history
Signed-off-by: Dariusz Duda <[email protected]>
  • Loading branch information
dariuszd21 authored Feb 27, 2025
1 parent df498f0 commit 1cd3cf7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions snap/local/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Dynamically load stage-package from another snap into our sys.path.
https://docs.python.org/3/library/site.html#module-sitecustomize
"""

import hashlib
import os
import sys
from pathlib import Path

TARGET_HASH = "8641d59472d54186f68939ab09cd4882cfba8f20efe278e6a539973c0b3e512c84d952e80f1d7297f8fd025e6878ea58"


def _find_pkg() -> None:
for craft_dir in Path("/snap").glob("*craft*/current"):
hasher = hashlib.sha3_384()
hasher.update(str(craft_dir).encode())
pkg_dir_hash = hasher.hexdigest()
if pkg_dir_hash != TARGET_HASH:
continue
pkg_path = craft_dir / "craft-plugins"
sys.path.insert(0, os.fspath(pkg_path))
return


_find_pkg()
4 changes: 4 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ parts:
plugin: dump
organize:
craft.git: libexec/snapcraft/craft.git
# Put sitecustomize in site-packages
sitecustomize.py: lib/python3.12/site-packages/sitecustomize.py

stage:
- "libexec/"
- "lib/"

git:
plugin: nil
Expand Down

0 comments on commit 1cd3cf7

Please sign in to comment.