Core20 python plugin not snapping (works on core18)

I have the following snapcraft.yaml file:

name: my-script
base: core18
version: '1.2.3'
summary: Summary
description: |
  Description

grade: devel
confinement: devmode

parts:
  my-script:
    plugin: python
    source: .
    source-type: local

apps:
  my-script:
    environment:
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
    command: my-script

and it creates a snap file without issues.

When I change core18 to core20 and build the snap again (after cleaning, etc.) I get an error regarding missing wheel: error: invalid command 'bdist_wheel'

  Building wheel for myscript (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /root/parts/my-script/install/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-d7198e7i/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-d7198e7i/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-xkthfry_
       cwd: /tmp/pip-req-build-d7198e7i/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'
  ----------------------------------------
  ERROR: Failed building wheel for myscript
  Running setup.py clean for myscript
  Building wheel for PyYAML (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /root/parts/my-script/install/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xe3r4j94/PyYAML/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xe3r4j94/PyYAML/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-5j1iig_x
       cwd: /tmp/pip-install-xe3r4j94/PyYAML/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'
  ----------------------------------------
  ERROR: Failed building wheel for PyYAML
  Running setup.py clean for PyYAML
Failed to build myscript PyYAML

After changing the parts in my snapcraft.yaml file to:

parts:
  my-script:
    plugin: python
    python-packages:
      - pip
      - setuptools
      - wheel
    source: .
    source-type: local

the whole process runs OK, until the last step, where I get an error:

Staging my-script
Priming my-script
Failed to generate snap metadata: The specified command 'my-script' defined in the app 'my-script' is not executable.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

Here’s my setup.py file:

#!/usr/bin/env python
from setuptools import find_packages, setup

setup(
    name='My Script',
    version='1.2.3',
    packages=find_packages('src'),
    package_dir={'': 'src'},
    entry_points={"console_scripts": [
        "my-script = my_script.my_script:main"
    ]},
    author='Me',
    author_email='some@email.com',
    description='Desc',
    url='https://example.org',
    project_urls={
        "Source Code": 'https://example.org',
    },
    install_requires=[
        'PyYAML==5.3.1',
        'pyxdg==0.26'
    ]
)

I have the following directory structure:

.
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements-dev.txt
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ setup.py
β”œβ”€β”€ snap
β”‚   └── snapcraft.yaml
└── src
    └── my_script
        β”œβ”€β”€ my_script.py
        β”œβ”€β”€ __init__.py
        └── __version__.py

What should I change for snapping to work on core20? It works fine on core18.

Tested on:


$ which snapcraft
/snap/bin/snapcraft

$ which multipass
/snap/bin/multipass

$ snapcraft --version
snapcraft, version 4.0.2+git12.g389c180e

$ multipass --version
multipass  1.3.0-dev.55+gb82d487
multipassd 1.3.0-dev.55+gb82d487

Problem solved (?). The trick was to add bin/ before the script name, clean and build again:

    command: bin/my-script

Have you tried running directly my_script.py?

command: python $SNAP/my-script-location/my_script.py

edit: ops, you fixed it

No. It has to be run as a module (name == '__main__' runs tests). I could have used python -m ... (not tested!) but since I have auto-generated script by setuptools, I want to use that.

But still - it is strange, that core18 did not require the bin/ prefix to work… I have no idea why.

@damians core20 snaps will no longer search for the executable, instead requiring that the correct path to the executable be specified in the YAML.

2 Likes