canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
35 stars 43 forks source link

Python plugin failing to find Python binary #225

Closed arturo-seijas closed 1 year ago

arturo-seijas commented 1 year ago

Hi!

I'm trying to build a rock that was succeeding last week but now I'm getting an error stating No suitable Python interpreter found, giving up.. Has the python plugin interface changed or is this perhaps a regression?

Below is the failing snippet:

name: indico-nginx
summary: Indico nginx rock
description: Nginx OCI image for the Indico charm
version: "1.0"
base: bare
build-base: ubuntu:22.04
license: Apache-2.0
platforms:
  amd64:
parts:
  indico-files:
    build-packages:
      - build-essential
      - libpq-dev
      - python3-dev
      - python3-pip
    plugin: python
    source: .
    python-packages:
      - indico==3.2.0
    organize:
      lib/python3.10/site-packages/indico/web/static: srv/indico/static
    stage:
      - srv/indico/static

Thank you very much

tigarmo commented 1 year ago

Hi. None of the bases (ubuntu or bare) provide the python binary so we added a check (the error you're seeing) to make sure rockcraft doesn't create ROCKs that need Python but don't have it. The fix in this case is to add something like python3-venv as a stage-package.

However, from your yaml it looks like maybe you don't actually need Python at runtime, is that the case?

arturo-seijas commented 1 year ago

Hi. None of the bases (ubuntu or bare) provide the python binary so we added a check (the error you're seeing) to make sure rockcraft doesn't create ROCKs that need Python but don't have it. The fix in this case is to add something like python3-venv as a stage-package.

However, from your yaml it looks like maybe you don't actually need Python at runtime, is that the case?

Exactly. I don't need Python at runtime, just some contents of the Python package I'm installing

tigarmo commented 1 year ago

Ah I see. For now you'll have to include python3-venv as a stage-package to make the Python plugin happy, but your stage entry should keep it from being added to the ROCK.

arturo-seijas commented 1 year ago

Ah I see. For now you'll have to include python3-venv as a stage-package to make the Python plugin happy, but your stage entry should keep it from being added to the ROCK.

Understood. Thanks

PawelLipski commented 1 year ago

Hey @tigarmo ... I've just found this issue. I'm experiencing the same problem, even with stage-packages: [python3-venv] or stage-packages: [python3.10-venv] ☹️ I've tried a couple different things at https://github.com/VirtusLab/git-machete/pull/972/files#diff-56759910381a014fecfd7556dd72ddd68c747d922a5b7df2044b9ce7c552f5f5... to no avail, still getting:

Executing parts lifecycle: build git-machete
Executing action
execute action git-machete:Action(part_name='git-machete', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
load state file: /root/parts/git-machete/state/pull
fix artifacts: unpack_dir='/root/parts/git-machete/install'
remove directory /root/parts/git-machete/build
:: + set -x
:: + which python
:: + true
:: + which python3
:: /usr/bin/python3
:: + echo /root/parts/git-machete/install/bin:/snap/snapcraft/9362/libexec/snapcraft:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
:: /root/parts/git-machete/install/bin:/snap/snapcraft/9362/libexec/snapcraft:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
:: + python3 --version
:: Python 3.10.6
:: + id
:: uid=0(root) gid=0(root) groups=0(root)
:: + mkdir -p /root/stage/usr/bin
:: ++ which python3
:: + ln -s /usr/bin/python3 /root/stage/usr/bin/python3.10
:: + craftctl default
Executing PosixPath('/root/parts/git-machete/run/build.sh')
:: + python3 -m venv /root/parts/git-machete/install
:: + PARTS_PYTHON_VENV_INTERP_PATH=/root/parts/git-machete/install/bin/python3
:: + /root/parts/git-machete/install/bin/pip install -U pip setuptools wheel
:: Requirement already satisfied: pip in /root/parts/git-machete/install/lib/python3.10/site-packages (22.0.2)
:: Collecting pip
::   Downloading pip-23.1.2-py3-none-any.whl (2.1 MB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 34.5 MB/s eta 0:00:00
:: Requirement already satisfied: setuptools in /root/parts/git-machete/install/lib/python3.10/site-packages (59.6.0)
:: Collecting setuptools
::   Downloading setuptools-67.8.0-py3-none-any.whl (1.1 MB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 89.1 MB/s eta 0:00:00
:: Collecting wheel
::   Downloading wheel-0.40.0-py3-none-any.whl (64 kB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.5/64.5 KB 10.9 MB/s eta 0:00:00
:: Installing collected packages: wheel, setuptools, pip
::   Attempting uninstall: setuptools
::     Found existing installation: setuptools 59.6.0
::     Uninstalling setuptools-59.6.0:
::       Successfully uninstalled setuptools-59.6.0
::   Attempting uninstall: pip
::     Found existing installation: pip 22.0.2
::     Uninstalling pip-22.0.2:
::       Successfully uninstalled pip-22.0.2
:: Successfully installed pip-23.1.2 setuptools-67.8.0 wheel-0.40.0
:: + '[' -f setup.py ']'
:: + /root/parts/git-machete/install/bin/pip install -U .
:: Processing /root/parts/git-machete/build
::   Preparing metadata (setup.py): started
::   Preparing metadata (setup.py): finished with status 'done'
:: Building wheels for collected packages: git-machete
::   Building wheel for git-machete (setup.py): started
::   Building wheel for git-machete (setup.py): finished with status 'done'
::   Created wheel for git-machete: filename=git_machete-3.17.5-py2.py3-none-any.whl size=85137 sha256=6b5e90a8fd4220c8ee03badef525ca60bf76a5f1a0d55879a6f97b0852e66d0d
::   Stored in directory: /tmp/pip-ephem-wheel-cache-um10ktx8/wheels/01/22/50/795ed6e9da0014a091d32e884a111523aecece28f2e2ad0cab
:: Successfully built git-machete
:: Installing collected packages: git-machete
:: Successfully installed git-machete-3.17.5
:: + find /root/parts/git-machete/install -type f -executable -print0
:: + xargs -0 sed -i '1 s|^#\!/root/parts/git-machete/install/bin/python3.*$|#!/usr/bin/env python3|'
:: ++ set +o
:: ++ grep errexit
:: + opts_state='set +o errexit'
:: + set +e
:: + install_dir=/root/parts/git-machete/install/usr/bin
:: + stage_dir=/root/stage/usr/bin
:: ++ find /root/parts/git-machete/install/usr/bin /root/stage/usr/bin -type f -executable -name 'python3.*' -print -quit
:: + payload_python=
:: + '[' -n '' ']'
:: + symlink_target=
:: + '[' -z '' ']'
:: + echo 'No suitable Python interpreter found, giving up.'
:: No suitable Python interpreter found, giving up.
:: + exit 1
:: error: Failed to run the build script for part 'git-machete'.
'override-build' in part 'git-machete' failed with code 1.
:: Review the scriptlet and make sure it's correct.

Can you think of any other reason? I've only first observed this issue on Friday June 16th... is it a matter of some new update to snapcraft? 🤔

tigarmo commented 1 year ago

Hi @PawelLipski, this is for a Snap and not a ROCK, right? In that case, you likely need to explicitly declare extra python packages because the "dependency resolver" in core22 with classic confinement is a bit wonky. It finds the packages (python3.10-minimal, for example) in the base (core22), but then it can't be used because of the confinement.

Edit: as for the recency: Snapcraft 7.4.3 was made stable last week, and this is probably the case. To be clear, the previous behavior was working basically out of concidence, as it was using the host's Python installation which is a bad idea.

PawelLipski commented 1 year ago

Gr8! 🎉 thanks, adding python3.10-minimal to stage-packages indeed fixed the problem