Simple Python snapcraft.yml

Can someone explain in detail how do I complete this snapcraft.yaml:
https://gist.github.com/wieczorek1990/4143227ebcd377b2ceccb69abaedb16d
for my project to successfully build?


The project is basically a Makefile, one sh file and one Python file and a readme.

I would read up on using the make plugins.

The python plugin is used when your app uses a setup.py.

It does:

  • import python modules with a requirements.txt
  • build a python project that has a setup.py
  • install packages straight from pip

So in this case you are likely going to have to add the various stage and build packages (dependencies). I had a look at your repo, and there are no deps listed, so I assume it is just python itself?

Actually - looking at what your makefile does - it’s current form will not work for a snap as you hardcode paths that are in system locations. And looking at what you make file actually does… I would just use hte dump plugin and move the commands into the yaml itself.

Yes, it’s just Python. The Bash script is just an alias.

Thanks for reply. Will try.

Ok, here is a working build. But it is currently in devel/devmode. So I have not worked on the confinement aspects.

name: gitl
version: '1.0'
summary: Git loop
description: Git loop inspired by gitsh.
grade: devel
confinement: devmode

parts:
  gitl:
    plugin: dump
    source: https://github.com/wieczorek1990/gitl.git
    source-type: git
    prepare: |
      chmod +x gitl.py
    organize:
      gitl.py: bin/gitl.py
    stage-packages:
      - python3

apps:
  gitl:
    command: bin/gitl.py

I dropped the makefile, ignored the alias and just exposed the script as the same name as your alias.

Clarification - I know there is additional work to be done. I know there is an execution issue once the snap is installed. If you have not figured it out, I’ll watch out here and circle back later (heading out hte door).

For reference the error is:

/snap/gitl/x1/command-gitl.wrapper: 6: exec: /snap/gitl/x1/bin/gitl.py: not found

So I have an error in my yaml.

1 Like

Yeah strange.

exec /snap/gitl/$x/bin/gitl.py

works as expected, maybe that’s a shell issue?

EDIT:
Can you clarify why adding stage-packages is necessary?

EDIT 2:
I’ve changed the repository layout to have bin in /.

EDIT 3:
Figured out the state-packages is just for dependency.

EDIT 4:
I’m on Fedora.

Well that’s good to know that is supporting for you. My shell “shouldn’t” matter. Hmmm. Gears turning…

Turned out that the state-packages uses different python that is 3.5 which is available during ‘snap run’.
Now I’m trying to figure out how to load user .gitconfig during ‘snap run’. ‘snap run --shell $app’ was helpful.

What version do you need? It is based on the repos for 16.04 (base snap core image)

3.5 is OK.
If the snap runs in sandbox how do I pass the user dotfiles?

Is there a way to prevent HOME being overwriteen by snap?

I’m out on my mobile, but traditionally snaps cannot access dot files (by design) even with the home plugin enabled. Are these dotfiles config for your app? Or something else?

Found the app plug home.