Run python script in configure hook

Hey,

as part of my configure hook I am trying to run a python-based executable file that is part of the snap. But it seems like the sys.path is different because it cannot find the packages installed under $SNAP/lib/python3.6/site-packages/ . Is this on purpose and if so what alternative should one use?

1 Like

This is likely due to https://bugs.launchpad.net/snapcraft/+bug/1824255. For a workaround, since snapcraft doesn’t currently define any wrappers for hooks and doesn’t use command-chain for hooks, you can manually define a command-chain for your hook with passthrough, and then as long as you specify adapter for one of your apps (to make snapcraft generate the wrapper that’s used) the wrapper should get defined for you to use with passthrough. Try something like this:

assumes: [command-chain]
passthrough:
  hooks:
    configure:
      command-chain:
      - snap/command-chain/snapcraft-runner

apps:
  mything:
    adapter: full
...

Thanks! I’ll look into that. I also found this teaser of an explanation “As mentioned in the docs, there are two ways to create hooks using snapcraft. If we were writing hooks in, say, Python, we’d want to use the second method so Snapcraft defines an environment for us.” [1] There is a link there and I read the text on the linked page, but I see no description of an alternative way that sets up an environment correctly.

[1] https://snapcraft.io/blog/snap-install-time-setup-the-install-hook

Thanks, it worked! I ended up adding all the paths as is described in the bug report in order to avoid being flagged by the store.

1 Like