使用RPM分发python软件包以及模块依赖项 [英] Distributing a python package along with module dependencies using RPM

查看:322
本文介绍了使用RPM分发python软件包以及模块依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个由脚本/模块组成的python应用程序,应将其打包并部署为RPM.

I've got several python applications consisting of scripts/modules that should be packaged and deployed as RPMs.

更棘手的一点是,每个应用程序都应与所有python模块依赖项一起分发,并且应优先于所有在系统范围内安装的应用程序使用.

The trickier bit is that each application should be distributed along with all python module dependencies, and these should be used in preference to any that are installed system wide.

其中一些RPM的目标主机具有有限的网络访问权限,因此RPM应该包含运行该应用程序所需的所有内容,而不是在部署时下载任何内容.

The target hosts for some of these RPMs have limited network access, so the RPMs should contain everything needed to run the app, rather than downloading anything at deploy time.

我已经研究过打包和分发 virtualenv ,但是重定位virtualenv并没有"似乎得到了很好的支持.

I've looked at packaging and distributing a virtualenv, but relocating a virtualenv doesn't seem to be well supported.

我查看了 zc.buildout ,但是发现缺少文档.我可以看到如何在开发过程中下载依赖项,但看不到如何将其作为大型应用程序的一部分进行分发.可能不同的应用程序需要同一模块的不同版本,因此不应在系统范围内安装这些模块.

I've looked at zc.buildout, but found the documentation to be lacking. I could see how to download dependencies during development, but not how to distribute them as part of a larger application. It's possible different apps require different versions of the same module, so these shouldn't be installed system wide.

另一个痛苦点是,在开发过程中和部署之后,需要修改应用程序中的所有python脚本以使用不同的sys.path,我看不出有明显的解决方法.

Another pain point is that any python scripts in the app need to be modified to use a different sys.path during development and after deployment, I couldn't see an obvious way around this.

关于如何最好地实现这一目标的建议吗?从开发人员的角度来看,理想的工作流摘要应该是:

Are suggestions on how best to achieve this? An ideal summary of the workflow from a developer's point of view would look like:

  1. 下载应用程序源
  2. 运行脚本以获取特定的模块依赖项(如果不存在的话)(也许使用 pip )
  3. 运行脚本以构建python应用,并将其和所有下载的依赖项打包到RPM中
  1. download application source
  2. run script to fetch specific module dependencies if not present (perhaps using pip)
  3. run script to build python app, and package it and all downloaded dependencies into RPM

然后,最终RPM应该可以在没有网络访问权限的主机上安装和运行,并且只能安装python解释器.

The final RPM should then be installable and runnable on a host with no network access, and only a python interpreter installed.

推荐答案

我将其视为两个独立的问题.

I'd see it as two separate problems.

  1. 您想要为开发人员提供可重复的安装/构建系统.

  1. You want a repeatable install/build system for your developers.

您需要安装程序生成器.

You want an installer builder.

构建(或与其他脚本结合使用的点子)可以解决第一个问题.基本上是:如何使项目准备好在新的笔记本电脑上进行开发".理想情况下,您只需说python bootstrap.py;bin/buildout并做好准备(与pip/virtualenv相同).

Buildout (or pip, perhaps in combination with an extra script) can take care of the first problem. Basically: "how to get the project ready for development on a fresh laptop". Ideally you'd just say python bootstrap.py;bin/buildout and be ready (same with pip/virtualenv).

既然您具有可重复的构建,则可以将其用作安装程序的基础.最方便的是仅用于此目的的干净虚拟机.例如,Virtualbox/vagrant.制作用于设置virtualbox并在其中安装适当依赖项的脚本.

Now that you have a repeatable build, you can use that as the basis for an installer. Handiest is a clean virtual machine that you use just for this purpose. Virtualbox/vagrant, for instance. Make scripts that set up the virtualbox and that install the proper dependencies in there.

然后,安装程序生成器脚本可以在虚拟框内对项目进行全新签出,并在您希望将其放入安装程序的位置(例如,/opt/yourproject)进行可重复的构建.

The installer builder script can then make a fresh checkout of your project inside the virtualbox and do the repeatable build thingy in the location where you want to have it in the installer (/opt/yourproject, for instance).

然后使用 FPM 制作实际的程序包(.deb,.rpm等).传递FPM选项以告知其必要的依赖关系,这样您就可以始终确保已安装了这些依赖关系. (注意:这些是操作系统级别的依赖项,例如memcached或postgres; python依赖项应通过pip或buildout处理.)

Then use FPM to make the actual package (.deb, .rpm, whatever). Pass in FPM options that tells it about the necessary dependencies, this way you can always be sure those dependencies are installed. (Note: these are OS-level dependencies like memcached or postgres; the python dependencies should be handled by pip or buildout).

如果将大问题分解为两个小问题,则可以分别对它们进行攻击.

If you split up your big problem in these two smaller problems, both can be attacked separately.

这篇关于使用RPM分发python软件包以及模块依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆