1

I am trying to create a snap package of a Python app (trespass). I have uploaded it to pypi and it pip installs on Arch and Ubuntu, oddly to /usr/bin/trespass on Arch and to /usr/local/bin/trespass on Ubuntu.

When I try to build the snap it fails.

This is my first pypi package and first attempt at a snap. So it's highly likely I'm doing it wrong.

Here is the dev directory on Arch

[grahams@CQ5110F trespass]$ tree
.
├── build
│   ├── lib
│   │   └── trespass
│   │       └── trespass.py
│   └── scripts-3.6
│       ├── trespass
│       └── trespass.py
├── dist
│   ├── trespass-0.6.5.4.tar.gz
│   └── trespass-0.6.5.5.tar.gz
├── License
├── MANIFEST
├── README.md
├── README.txt
├── setup.cfg
├── setup.py
└── trespass
    └── trespass

My setup.py looks like this

from distutils.core import setup
setup(
  name = 'trespass',
  packages = ['trespass'], # this must be the same as the name above
  install_requires=[
    'numpy',
    'pygpgme',
    'pyperclip',
    'argparse',
  ],
  version = '0.6.5.5',
  description = 'A secure password keeper', 
  author = 'Graham Smith',
  author_email = 'gps1539@gmail.com',
  scripts = ['trespass/trespass'],
  license='GPL3',
  url = 'https://github.com/gps1539/trespass', # use the URL to the github repo
  download_url = 'https://github.com/gps1539/trespass/archive/0.1.tar.gz',
  keywords = ['testing', 'logging', 'example'], # arbitrary keywords
  classifiers = [],
)

On Ubuntu my snapcraft.yaml looks like this.

name: trespass
version: '0.6.5.4' 
summary: A secure command line password keeper using gpg 
description: |

grade: devel
confinement: devmode

apps:
  trespass:
    command: usr/bin/trespass

parts:
  trespass:
    plugin: python
    python-version: python3
    source: https://github.com/gps1539/trespass/archive/0.1.tar.gz
    build-packages:
      - python3-gpgme
      - python3-numpy
      - python3-pyperclip

When I try to build I get the following output

root@graham-VirtualBox:~/trespass-snap/snap# sudo snapcraft clean
Cleaning up priming area
Cleaning up staging area
Cleaning up parts directory
root@graham-VirtualBox:~/trespass-snap/snap# sudo snapcraft
Preparing to pull trespass 
Hit http://us.archive.ubuntu.com/ubuntu artful InRelease                            
Get:1 http://security.ubuntu.com/ubuntu artful-security InRelease [76.7 kB]         
Get:2 http://us.archive.ubuntu.com/ubuntu artful-updates InRelease [78.6 kB]        
Hit http://us.archive.ubuntu.com/ubuntu artful-backports InRelease                  
Fetched 155 kB in 0s (0 B/s)                                                        
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3.6-minimal_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libsqlite3-0_3.19.3-3_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3.6-stdlib_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/gcc-7-base_7.2.0-8ubuntu3_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3.6_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/mime-support_3.60ubuntu1_all.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libmpdec2_2.4.2-1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libexpat1_2.2.3-1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3.6-minimal_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3-minimal_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3-stdlib_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/dh-python_2.20170125_all.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libreadline7_7.0-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libffi6_3.2.1-6_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libssl1.0.0_1.0.2g-1ubuntu13.2_amd64.deb
Pulling trespass 
Downloading '0.1.tar.gz'|                                                            
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 733kB/s 
  Saved ./parts/trespass/packages/pip-9.0.1-py2.py3-none-any.whl
Collecting setuptools
  Downloading setuptools-36.7.0-py2.py3-none-any.whl (482kB)
    100% |████████████████████████████████| 491kB 1.8MB/s 
  Saved ./parts/trespass/packages/setuptools-36.7.0-py2.py3-none-any.whl
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    100% |████████████████████████████████| 51kB 3.2MB/s 
  Saved ./parts/trespass/packages/wheel-0.30.0-py2.py3-none-any.whl
Successfully downloaded pip setuptools wheel
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Collecting setuptools
Collecting wheel
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.7.0 wheel-0.30.0
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Preparing to build trespass 
Building trespass 
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Collecting setuptools
Collecting wheel
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.7.0 wheel-0.30.0
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Staging trespass 
Priming trespass 
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.34+17.10', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 564, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2662, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2316, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2322, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__main__.py", line 19, in <module>
    run(prog_name='snapcraft')
  File "/usr/lib/python3/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__init__.py", line 110, in run
    ctx.forward(lifecyclecli.commands['snap'])
  File "/usr/lib/python3/dist-packages/click/core.py", line 553, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 132, in snap
    project_options, directory=directory, output=output)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 349, in snap
    execute('prime', project_options)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 130, in execute
    _Executor(config, project_options).run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 228, in run
    self._create_meta(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 269, in _create_meta
    self.config.snapcraft_yaml_path)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 84, in create_snap_packaging
    packaging.write_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 111, in write_snap_yaml
    snap_yaml = self._compose_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 276, in _compose_snap_yaml
    snap_yaml['apps'] = self._wrap_apps(self._config_data['apps'])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 385, in _wrap_apps
    self._wrap_app(app, apps[app])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 392, in _wrap_app
    app[k] = self._wrap_exe(app[k], '{}-{}'.format(k, name))
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 365, in _wrap_exe
    with open(exepath, 'rb') as exefile:
FileNotFoundError: [Errno 2] No such file or directory: '/home/graham/trespass-snap/snap/prime/usr/bin/trespass'

Original thread is here, but the snapcraft forum block the topic due to too many links: https://forum.snapcraft.io/t/how-to-call-dependencies-in-snapcraft-yaml/2726/8

halfer
  • 19,824
  • 17
  • 99
  • 186
user192749
  • 247
  • 1
  • 3
  • 11
  • Where do you have that setup.py? It is not on https://github.com/gps1539/trespass/archive/0.1.tar.gz – elopio Nov 10 '17 at 23:13
  • Well spotted. I needed to create an update tag. Now it gets past that issue, but due to a missing header file – user192749 Nov 11 '17 at 00:30
  • Side Note gpgme.h is missing on Ubuntu, have to add libgpgme-dev rather than python3-gpgme, now pygpgme installs. – user192749 Nov 11 '17 at 00:53
  • Made progress but still can not get the snap to build. No space to add the output, will ask a 2nd question and link here. – user192749 Nov 11 '17 at 01:11
  • @user192749, does it work if you change command to `/usr/local/bin/trespass` . Anyway snapcraft now using VM setup to build snaps, so you will get same behavior in most platforms. – user.dz Apr 22 '20 at 13:17
  • Alas, I gave up on snaps, far too hard to understand for an amateur dev like me – user192749 Apr 23 '20 at 16:47

1 Answers1

0

Your setup.py needs to be inside the https://github.com/gps1539/trespass/archive/0.1.tar.gz used as source.

elopio
  • 191
  • 1
  • 8