分发依赖于内部通用便利库的 Python 包

发布于 2024-10-07 12:53:18 字数 574 浏览 6 评论 0 原文

我有一些 Python 包,我想整理并发布在 PyPI 上。这些包导入了我编写的几个 Python 模块,以增强或简化某些操作(例如,通过包装 csv 函数),提供方便的数据结构等。目前这些模块位于保存我的项目代码的顶级目录中,并且我依靠将该目录添加到我的 PYTHONPATH 环境变量中来访问它们。 (我知道,不太整洁。)

通过为这些模块创建一个单独的包并将它们上传到 PyPI,我可以将这样的包标记为我实际想要分发的包的依赖项。然而,这些便利模块很小,用途和兴趣有限,因此我认为它们不值得在 PyPI 上作为单独的包分发。另一方面,我犹豫是否将这些便利模块(即,使用 cp pleasure_module.py projectX/.)复制到每个项目目录中,因为这会在 VCS 中创建同一文件的多个副本存储库包含我的 Python 代码以及我将发布到 PyPI 的不同源发行版 tarball。这个问题有优雅的解决方案吗?

I have a few Python packages that I would like to tidy up and publish on PyPI. These packages import a couple of Python modules I've written to augment or simplify certain operations (e.g., reading/writing from CSV files with headers by wrapping csv functions), provide handy data structures, etc. Currently these modules are housed in the top-level directory that holds the code for my projects, and I rely on reaching them by having added that directory to my PYTHONPATH environmental variable. (Less than tidy, I know.)

By creating a separate package for these modules and uploading them on PyPI, I could mark such a package as a dependency for the packages I actually want to distribute. These convenience modules are, however, small and of limited use and interest, such that I don't think they warrant distributing as a separate package on PyPI. On the other hand, I am hesitant to copy these convenience modules (i.e., use cp convenience_module.py projectX/.) into each project directory, as this creates multiple copies of the same file both in the VCS repository housing my Python code and in the different source distribution tarballs I would post to PyPI. Is there an elegant solution to this problem?

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

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

发布评论

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

评论(2

等风来 2024-10-14 12:53:18

您没有说明为什么您对“提供副本”犹豫不决。一般来说,我认为合理的方法是考虑如何为自己进行设置以使用便利模块。您是否将它们安装在站点包(或等效项)中,或者您只是依赖它们位于运行代码的目录中?无论您如何使用这些模块,这种情况是否理想,或者是否有更适合您的方法?

从这里开始,找出如何通过 setup.py 实现自动化,它可以让你把东西放在系统上任何你想要的地方(尽管我强烈反对滥用这种功能)。

无论您将它们作为 tarball 分发还是与需要它们的软件包一起分发,您仍然需要维护所有文件,因此唯一真正的问题是您是否打算让这些便利模块开发自己的用户具有自己的支持请求等的社区,或者它们是否明确仅用于支持此其他模块。

如果您希望这些模块仅用于一个模块,请将它们包含在包中,也许包含在发行版内的“utils”包中。否则,您只是将索引中的内容弄乱了,人们可能认为有用,但实际上与其他推动它们更改和维护的内容紧密相连。

如果您希望这些模块是通用的,并打算如此维护它们,并且认为它们在支持该模块之外还有用处,请单独分发它们。

You don't say why you're hesitant to 'provide copies'. In general, I think a reasonable approach is to think about how you've set things up for yourself to use the convenience modules. Did you install them in site-packages (or equivalent), or did you just depend on them being in the directory you ran the code from? However you use the modules, is that situation ideal, or is there a way that would be nicer for you?

Start with that, and figure out how to automate it through setup.py, which lets you put things wherever you want on the system (though I strongly discourage abusing this capability).

Whether you distribute them as a tarball or with the package that needs them, you still have to maintain all of the files, so the only real question is whether you intend for those convenience modules to develop their own user communities with their own support requests, etc., or whether they're decidedly intended only for use in support of this other module.

If you intend those modules to be used only for the one module, include them in the package, perhaps in a 'utils' package inside the distribution. Otherwise you're just cluttering the index with things people might think are useful, but are really joined at the hip with something else that drives the changes and maintenance of them.

If you intend those modules to be generic, and intend to maintain them as such, and think they have use outside of supporting this module, distribute them separately.

从来不烧饼 2024-10-14 12:53:18

据我所知,通过 PyPI 分发这些小包是唯一可行的选择。是的,它用几乎无用的包扰乱了索引,但它应该由 PyPI 维护者而不是包开发人员来解决。另一种选择是使用 stdlib 或其他 util 包的数据和函数,而不是重新发明轮子。

只要确保您像这样描述了 utils 包,或者将它们扩展为对其他人更有用的东西即可。

As far as I know, distributing these small packages via PyPI is only viable option. Yes, it clutters the index with near-useless packages, but its something that should be solved by PyPI maintainers, not package developers. Another alternative is to use stdlib's or other util packages data and functions rather than reinventing the wheel.

Just make sure you describe that utils package as such, or extend them in something more useful for others.

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