Snapcraft python 只打包依赖,不打包应用?
Snapcraft python only packages dependencies, not app?
我有一个非常标准的 python 应用程序,包括 setup.py
和 requirements.txt
,可以很好地安装 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
...
我想使用快照来构建和部署应用程序,并注意到 snapcraft
只安装我的应用程序的依赖项,而不是应用程序本身。它确实构建了一个轮子,但没有安装它:
$ 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
有谁知道为什么 myAPP
不是 pip 安装的一部分?
作为参考,snapcraft.yaml
在这个阶段非常简单,但我认为应该是所有需要的。 Snapcraft v2.27.1
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/
进度
我检查了构建应用程序后安装了哪些包:
$ 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
....
如果我随后手动重新 运行 pip install -U myAPP
,它确实会包含在 site-packages
中。看看我是否可以单独重复其他构建步骤。
通过修补 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
我有一个非常标准的 python 应用程序,包括 setup.py
和 requirements.txt
,可以很好地安装 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
...
我想使用快照来构建和部署应用程序,并注意到 snapcraft
只安装我的应用程序的依赖项,而不是应用程序本身。它确实构建了一个轮子,但没有安装它:
$ 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
有谁知道为什么 myAPP
不是 pip 安装的一部分?
作为参考,snapcraft.yaml
在这个阶段非常简单,但我认为应该是所有需要的。 Snapcraft v2.27.1
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/
进度
我检查了构建应用程序后安装了哪些包:
$ 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
....
如果我随后手动重新 运行 pip install -U myAPP
,它确实会包含在 site-packages
中。看看我是否可以单独重复其他构建步骤。
通过修补 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