在多个操作系统上创建 Python 发行版(鸡蛋)的最佳实践是什么

发布于 2025-01-07 02:59:13 字数 403 浏览 0 评论 0原文

我们是一家蟒蛇店。我们内部开发了不同的 python 包,并将部署到客户的环境(机器)上。

这就是我们的开发和发布周期的发生方式。

一旦开发人员完成了包的“测试”,就会准备好包的分发版(egg 文件)并将其推送到中央存档位置。当我们想要向客户部署我们的软件时,将下载相同的发行版(egg 文件)并将其安装在他们的环境中。

假设“测试”发生在多个操作系统上(以检查 API 跨平台的兼容性),准备发行版并将其推送到中央存档位置的最佳实践是什么。

归档服务器上是否最好有特定于操作系统的egg(例如samplepkg-1.0.0.win32.egg和samplepkg-1.0.0.linux.egg?不知道如何使用setuptools以这种方式准备它们。)或者有一个鸡蛋,因为跨平台的 API 保持不变?社区还遵循任何其他做法吗?

Ours is a python shop. We have different python packages developed inhouse and will be deployed onto customers' environments(machines).

This is how our development and release cycle happens.

Once developers complete "testing" of a package, a distribution(egg file) of the package is prepared and pushed to a central archiving place. WHen we want to deploy our software to Customers, the same distributions(egg files) will be downloaded and installed in their environment.

Assuming the "testing" happens on multiple operating systems(to check the compatibility of the API across platforms), what is the best practice to prepare distributions and be pushed to the central archiving place.

Is it best to have operating system specific eggs on the archiving server(like, samplepkg-1.0.0.win32.egg and samplepkg-1.0.0.linux.egg ? Not sure how they can be prepared in this way using setuptools. ) Or Have a single egg because API remains same across platforms ? Any other practice which is followed by the community ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只为守护你 2025-01-14 02:59:13

您可以使用单个包,如果:

  1. 该包不使用并非在所有目标平台上可用的函数/类(请参阅版本 2.7.2 的 Python 标准库参考的第 36-39 章,了解您不应该使用的内容在这种情况下使用)
  2. 您没有使用用 C/C++ 编写的需要为每个平台进行编译的扩展。

通常最好远离并非在所有目标平台上都可用的操作系统特定功能。标准库在这方面有很好的记录。

You can use a single package if:

  1. The package does not use functions/classes that are not available on all your target platforms (see e.g. chapters 36-39 of the Python standard library reference for version 2.7.2 for stuff that you shouldn't use in that case)
  2. You are not using extensions written in C/C++ that need to be compiled for every platform.

It it generally a good idea to stay away from OS specific functions that are not available on all your target platforms. The standard library is quite well documented in that respect.

千紇 2025-01-14 02:59:13

我认为在这种情况下,由于 Roland 上面提到的原因,使用单个包会更加复杂。在您的开发环境中,您可以为不同的平台设置单独的文件夹,每个文件夹都包含特定于平台的代码(例如用 C/C++ 编写的扩展/库)。您需要在这些文件夹中模仿您的 setuptools 来生成单独的 Egg,但它最终会比尝试将所有内容放入一个包中更简单(我认为,无需更多地了解您实际使用的代码)。

无论哪种情况,请阅读标准库以及 distutils 的文档 (http://docs.python.org /distutils/)应该可以帮助您找到解决方案。

I think that in this case, using a single package would be more complicated due to the reasons that Roland mentioned above. In your development environment you could have separate folders for separate platforms, each with the platform specific code (such as extensions/libraries written in C/C++). You would need to mimic your setuptools within these folders to produce separate eggs, but it would ultimately be less complex (I think, without knowing more about what code you are actually working with) than trying to put everything into one package.

In either case, reading the documentation on the standard library, as well as distutils (http://docs.python.org/distutils/) should help you find your solution.

怀中猫帐中妖 2025-01-14 02:59:13

特定于平台的 Egg 仅用于分发包含 C 代码的包;否则,egg 文件本身是与平台无关的,您只需分发一个与平台无关的 Egg。

如果您使用自动安装工具或 pkg_resources 的运行时 API 来查找库和插件,您实际上可以将所有 Egg 转储到一个目录中,安装工具或运行时 API 将选择要安装或导入的 Egg。

tl;dr 版本:setuptools 构建 Egg 的方式就是它们应该被分发的方式;如果您尝试将跨平台鸡蛋变成依赖于平台的鸡蛋,反之亦然,您可能会遇到一些痛苦。 ;-)

Platform-specific eggs are only intended for distributing packages containing C code; otherwise the egg files themselves are platform-independent and you only need to distribute one, platform-independent egg.

If you are using automated installation tools or pkg_resources' runtime APIs for finding libraries and plugins, you can actually just dump all the eggs in a single directory, and the installation tool or runtime API will pick which egg to install or import from.

tl;dr version: the way setuptools builds eggs is the way they should be distributed; if you try to make a cross-platform egg into a platform-dependent one or vice versa, you're likely to experience some pain. ;-)

请远离我 2025-01-14 02:59:13

如果您只有 python 模块,请将所有差异隐藏在 python 中,无论是相同的文件(python std lib)还是单独的文件(pyserial)。

如果您已经编译了模块,那就有点棘手了。

我对需要编译扩展的项目使用以下目录结构:

./lib/display.py  # frontend, platform-independent
./lib.linux-x86_64-2.6/_display.so
./lib.linux-armv5tejl-2.6/_display.so

并且此代码位于程序开头的开头:

sys.path.append("lib.%s-%s-%s.%s" % ((posix.uname()[0].lower(),
                                      posix.uname()[4])
                                     +sys.version_info[:2]))

您也可以将这样的结构包装在 .egg 中,只要您指定它不是 zip-safe 。

If you only have python modules, keep all the difference hidden in python, either same files (python std lib) or separate files (pyserial).

If you have compiled modules, it's a bit trickier.

I use the following directory structure for a project that needs compiled extension:

./lib/display.py  # frontend, platform-independent
./lib.linux-x86_64-2.6/_display.so
./lib.linux-armv5tejl-2.6/_display.so

And this code in the beginning of the beginning of the program:

sys.path.append("lib.%s-%s-%s.%s" % ((posix.uname()[0].lower(),
                                      posix.uname()[4])
                                     +sys.version_info[:2]))

You can wrap structure like this in an .egg too, as long as you specify that it's not zip-safe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文