1

I have a pretty standard python application, including setup.py and requirements.txt, which installs fine with pip:

$ pip install .
$ tree -L 1 env/lib/python3.5/site-packages/

env2/lib/python3.5/site-packages/
├── myAPP 
├── myAPP-0.1.0-py3.5.egg-info
...

I'd like to use snaps to build and deploy the application, and noticed that snapcraft only installs my app's dependencies, but not the app itself. It does build a wheel, but does not install it:

$ snapcraft
....
Building wheels for collected packages: myAPP, blist
...
Successfully built myAPP blist
/home/ubuntu/parts/myAPP/install/usr/bin/python3 -m pip install --user 
    --no-compile --disable-pip-version-check --no-index 
    --find-links /home/ubuntu/parts/myAPP/packages blist 
    <other_requirements> --no-deps --upgrade

Does anyone know why myAPP is not part of the pip install?

For reference, the snapcraft.yaml is super simple at this stage, but I think should be all that's needed. Snapcraft is v2.27.1 on Ubuntu 16.04

name: myAPP
version: '0.0.1'
summary: myAPP web application
description: |
  myAPP main web application

grade: devel 
confinement: strict

apps:
  myAPP:
    command: gunicorn myApp.wsgi
    daemon: simple
    plugs:
      - network-bind

parts:
  myAPP:
    plugin: python
    python-version: python3
    source: /opt/backend/

Progress

I checked what packages are installed after building the application:

$ parts/myAPP/install/bin/pip list --format columns
Package                 Version  Location           
----------------------- -------- -------------------
appdirs                 1.4.2    
blist                   1.3.6    
myAPP                   0.1.0    /opt/backend
....

If I then manually re-run pip install -U myAPP, it does get included into site-packages. Will see if I can repeat the other build steps separately.

4

1 回答 1

1

通过修补 snapcraft python 插件(在我的系统上/usr/lib/python3/dist-packages/snapcraft/plugins/python.py)找到了解决方法:

--- /usr/lib/python3/dist-packages/snapcraft/plugins/python.py  2017-02-17 13:45:14.000000000 +0000
+++ python.py   2017-03-02 01:53:54.993148168 +0000
@@ -298,7 +298,7 @@
                 # we want to avoid installing what is already provided in
                 # stage-packages
                 need_install = [k for k in wheel_names if k not in installed]
-                pip.install(need_install + ['--no-deps', '--upgrade'])
+                pip.install(wheel_names + ['--no-deps', '--upgrade', '--ignore-installed'])

     def _fix_permissions(self):
         for root, dirs, files in os.walk(self.installdir):

我希望这个问题可能有一个更清洁的解决方案?同时,您可以将上面的补丁复制到一个名为patch.diff并应用的文件中:

sudo patch -b /usr/lib/python3/dist-packages/snapcraft/plugins/python.py patch.diff
于 2017-02-28T00:01:59.923 回答