-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add sitecustomize for plugin loading (#5283)
Signed-off-by: Dariusz Duda <[email protected]>
- Loading branch information
1 parent
df498f0
commit 1cd3cf7
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters