Skip to content

Commit

Permalink
Fixes to make fades to actually work in a core20 snap.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundobatista committed Mar 22, 2022
1 parent f242306 commit cf9c879
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
9 changes: 8 additions & 1 deletion fades/envbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def __init__(self, env_path=None):
self.env_bin_path = ''
logger.debug("Env will be created at: %s", self.env_path)

if sys.version_info >= (3, 4):
if os.environ.get("SNAP"):
# running inside a snap: we need to avoid EnvBuilder ending up running ensurepip
# because it doesn't work properly (it does a special magic to run the script
# and ends up mixing external and internal pips)
self.pip_installed = False
super().__init__(with_pip=False, symlinks=True)

elif sys.version_info >= (3, 4):
# try to install pip using default machinery (which will work in a lot
# of systems, noticeably it won't in some debians or ubuntus, like
# Trusty; in that cases mark it to install manually later)
Expand Down
5 changes: 5 additions & 0 deletions fades/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def detect_inside_virtualenv(prefix, real_prefix, base_prefix):
https://github.com/pypa/pip/blob/281eb61b09d87765d7c2b92f6982b3fe76ccb0af/
pip/locations.py#L39
"""
if os.environ.get("SNAP"):
# snaps under core20 are really virtualenvs but we have full control of the
# system layout, "this is fine" (<insert meme>), skip this control
return False

if real_prefix is not None:
return True

Expand Down
30 changes: 24 additions & 6 deletions pkg/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,35 @@ adopt-info: fades # look for 'snapcraftctl set-*' in the fades part

apps:
fades:
command: bin/fades
environment:
PYTHONPATH: $SNAP/lib/python3.8/site-packages/
command: bin/python3 -m fades

parts:
# Classic core20 snaps require staged python.
python3:
plugin: nil
build-packages:
- python3-dev
stage-packages:
- libpython3-stdlib
- libpython3.8-minimal
- libpython3.8-stdlib
- python3.8-minimal
- python3-distutils
- python3-minimal
- python3-pkg-resources
- python3-pip
- python3-setuptools
- python3-venv
- python3-wheel

fades:
after: [python3]
source: .
plugin: python
requirements:
- requirements.txt
override-pull: |
snapcraftctl pull
snapcraftctl set-version "$( python3 -c 'import fades; print(fades._version.__version__)' )"
override-build: |
snapcraftctl build
# python3 fixup symlink (snapcraft bug)
ln -sf ../usr/bin/python3.8 $SNAPCRAFT_PART_INSTALL/bin/python3

0 comments on commit cf9c879

Please sign in to comment.