Snapcraft build fails

Trying to build an example snap and it fails the build. Just learning how snapcraft works, but this simple examples fails each time and I cannot identify what is going wrong. Any help would be appreciated.

CAPTURED DATA:

$ sudo snap install --classic snapcraft

Ubuntu Version: Ubuntu 16.04.5 LTS

$ python -V
Python 2.7.12
$ snapcraft --version
snapcraft, version 2.43.1
$ dpkg -l | grep build-esse
ii  build-essential                                             12.1ubuntu2                                  amd64        Informational list of build-essential packages
dumpinfo$ tree
.
├── dumpinfo
│   ├── dumpinfo.py
│   └── __init__.py
├── README
├── requirements.txt
├── setup.py
└── snap
    └── snapcraft.yaml

2 directories, 6 files
setup.py
=============================================
from setuptools import setup

setup(
   name='dumpinfo',
   version='1.0',
   description='Test Dump tool',
   author='John Doe',
   author_email='jdoe@foo.com',
   packages=['dumpinfo'],  #same as name
   install_requires=[], 
)
requirements.txt 
=============================================
simplejson
snapcraft.yaml
snapcraft.yaml 
name: dumpinfo
version: '0.1' 
summary: DumpInfo program
description: |
  This is a test program for creating a snap.

grade: devel 
confinement: devmode

parts:
  dumpinfo:
    plugin: python
    python-version: python2
    source: . 

apps:
  dumpinfo:
    command: bin/dumpinfo.py
dumpinfo.py
=============================================
#!/usr/bin/python
import json

test = { "fname":"John","lname":"Doe","age":42}
print json.dumps(test)
Error:
$ snapcraft
<Cut all the stuff that  went right>
.
.
.
.
Staging dumpinfo 
Priming dumpinfo 
Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 9, in <module>
    load_entry_point('snapcraft==2.43.1', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1037, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, 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/_runner.py", line 93, in run
    ctx.forward(lifecyclecli.commands["snap"])
  File "/usr/lib/python3/dist-packages/click/core.py", line 552, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 136, in snap
    project = _execute(steps.PRIME, parts=[], **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 35, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 90, in execute
    executor.run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 196, in run
    self._create_meta(step, processed_part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 359, in _create_meta
    self.config.validator.schema,
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 109, in create_snap_packaging
    packaging.write_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 312, in write_snap_yaml
    snap_yaml = self._compose_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 468, in _compose_snap_yaml
    snap_yaml["apps"] = self._wrap_apps(self._config_data["apps"])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 567, in _wrap_apps
    self._wrap_app(app, apps[app])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 575, in _wrap_app
    app[k] = self._wrap_exe(app[k], "{}-{}".format(k, name))
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py", line 546, in _wrap_exe
    with open(exepath, "rb") as exefile:
FileNotFoundError: [Errno 2] No such file or directory: '/home/myuser/Development/Python/dumpinfo/prime/bin/dumpinfo.py'
We would appreciate it if you created a bug report at
https://launchpad.net/snapcraft/+filebug with the above text included.

Executing
dumpinfo$ ls prime/bin/

Returns nothing

Can you please paste your snapcraft.yaml with the formatting? You can use markup language to paste it so that we know that the snapcraft.yaml format is correct.

I am assuming it looks like this:

snapcraft.yaml

version: ‘0.1’
summary: DumpInfo program
description: |
This is a test program for creating a snap.

grade: devel
confinement: devmode

parts:
  dumpinfo:
    plugin: python
    python-version: python2
    source: .

apps:
  dumpinfo:
    command: bin/dumpinfo.py

Thanks,
Luke

You nailed it except the line under description “This is a test program for creating a snap.” is indented a bit.

I see no entry points or scripts defined in that setup.py, which means bin/dumpinfo.py probably doesn’t exist. But you’ve defined an app that uses it, which is confusing snapcraft.

What would that look like? My setup.py file looks as such right now:
from setuptools import setup

setup(
name=‘dumpinfo’,
version=‘1.0’,
description=‘Test Dump tool’,
author=‘John Doe’,
author_email=‘jdoe@foo.com’,
packages=[‘dumpinfo’], #same as name
install_requires=[‘simple_json’],
scripts=[‘dumpinfo.py’]
)

Also, seemed to have gotten around original build issue, but getting the following:
Processing /home/tepkes/Development/Python/dumpinfo/parts/setup/src
Link is a directory, ignoring download_dir
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/dumpinfo.egg-info
writing pip-egg-info/dumpinfo.egg-info/PKG-INFO
writing top-level names to pip-egg-info/dumpinfo.egg-info/top_level.txt
writing dependency_links to pip-egg-info/dumpinfo.egg-info/dependency_links.txt
writing manifest file ‘pip-egg-info/dumpinfo.egg-info/SOURCES.txt’
error: package directory ‘dumpinfo’ does not exist

----------------------------------------

Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-req-build-iaIpjs/
Failed to run ‘/home/tepkes/Development/Python/dumpinfo/parts/setup/install/usr/bin/python2 -m pip download --disable-pip-version-check --dest /home/tepkes/Development/Python/dumpinfo/parts/setup/python-packages simple_json .’: Exited with code 1.

Which could be part of my setup.py problem. Any help here would be greatly appreciated. Thanks

You’ve just got good old python issues, now. Have you tried just getting this working in a virtual environment before trying to snap it? Get that working, and the snap will work as well. I’d be happy to help with that if you create a github repo with the project as it stands now, then I can clone it and tell you what the issues are.

I actually got it to build, I found the issue in the setup file, I had a setup.py outside of the src dir that it was latching on to. So now it builds, but I get the following:
$ snap list
Name Version Rev Tracking Publisher Notes
core 16-2.36.2 6034 stable canonical✓ core
dumpinfo 0.1 x1 - - devmode
snapcraft 3.0.1 2374 stable canonical✓ classic

$ ls /snap/bin
dumpinfo snapcraft
$ dumpinfo
/snap/dumpinfo/x1/command-dumpinfo.wrapper: 5: exec: /snap/dumpinfo/x1/bin/dumpinfo.py: not found

$ ls /snap/dumpinfo/x1/bin/dumpinfo.py
/snap/dumpinfo/x1/bin/dumpinfo.py <— so it exists

$ /snap/dumpinfo/x1/bin/dumpinfo.py
{“lname”: “Doe”, “age”: 42, “fname”: “John”} <— executing this gives me the right output

So in the tree, dumpinfo.py is in the dumpinfo/ directory. From what I gather havok4u is trying to use the python plugin to install the dumpinfo.py to bin/.

Yes. The python plugin isn’t magic though-- a proper setup.py is needed to make that happen.

Make sure dumpinfo.py is executable.

It is as I can execute it by doing the following command: /snap/dumpinfo/x1/bin/dumpinfo.py d

Also here is my tree:

Development/Python/dumpinfo$ tree
.
├── snap
│ └── snapcraft.yaml
└── src
├── dumpinfo.py
├── init.py
├── README
├── requirements.txt
└── setup.py

2 directories, 6 files

what is the shebang line stating on your dumpinfo.py file?

If it has an absolute path to python then it won’t work without modifying (e.g. #!/usr/bin/python3). The normal way to fix that is to change it to something like:

#!env python3

Changed to #!env python2
and it didn’t work, but changed to
#!/usr/bin/env python2
and it works now. Thanks

1 Like