如何处理专有Python包名称与公共包名称冲突的情况?

发布于 2024-11-18 21:43:38 字数 1221 浏览 1 评论 0原文

背景与

我一起工作的小组一直在使用和开发一个 Python 包,为了解决这个问题,我将其称为 foobuilder。我们使用为用户提供的私有 RPM 和 Deb 存储库为 Linux 系统提供更新。

最近,PyPi 中添加了一个同名的公共包。它还被打包到公共 Debian 存储库等地方。由于我们不公开宣传我们的软件包,因此出现同名软件包是可以理解的。

关注点

对于 foobuilder 来说,这看起来是一个大问题,因为在某个地方,用户可能会尝试安装我们的 foobuilder,而公共 foobuilder 包却在安装在同一系统上。

除了 Python 中的明显问题之外,我猜想将我们的存储库添加到 Debian 包管理器程序也可能会导致一些问题,尽管我还没有遇到过这种情况。

问题

由于我们多年来一直使用专有的 foobuilder ,存在大量想要导入 foobuilder 并期望获取我们的包的代码,所以我不认为改名不太可行。

我对可能的解决方案的想法

Python

我考虑过将包的名称更改为my_foobuilder,并让它包含一个名为foobuilder的元包,它仅包含一个>__init__.pymy_foobuilder 导入所有内容。我可以指导新用户直接导入 my_foobuilder。然后我就可以开始弃用 foobuilder 名称了。最终,这将导致与我现在将 foobuilder 更改为 my_foobuilder 相同的工作量,因为每个人都需要提供更新和 foobuilder code> name 不能永远处于弃用炼狱中。

Debian

Debian 的问题应该不难解决;我可以将 debian 软件包名称更改为 my_foobuilder,但仍然安装相同(冲突)的 Python 软件包。然后,我可以将 my_foobuilder 包与 foobuilder 设置为 Conflict。它可能需要用户摆弄他们的包管理器,以便在过渡期间让事情回到正轨,但我认为这没什么大不了的。尽管如此,这仍然阻止用户同时使用公共 foobuilder 包。

问题

有没有比我上面考虑的方法更简单或更好的方法来治疗这种情况?我正在考虑的解决方案有什么问题吗?你会如何处理这个问题?

Background

The group I work with has been using and developing a Python package, which for the purposes of this question I'll call foobuilder. We serve updates for Linux systems using private RPM and Deb repositories we provide for our users.

Recently, a public package was added to PyPi with the same name. It also got packaged on the public Debian repository, among other places. Since we don't publicly advertise our package, it's understandable that a package with the same name has popped up.

Concerns

This looks like a big problem for foobuilder because somewhere down the line, a user might try to install our foobuilder while the public foobuilder package is installed on the same system.

Besides the obvious problem in Python, I would guess that adding our repository to a Debian package manager program could also cause some issues, though I haven't played around with this situation yet.

Problem

Since we've been using the proprietary foobuilder for years, there is a ton of code in existence which wants to import foobuilder and expects to get our package, so I don't think it's feasible to change the name.

My thoughts on possible solutions

Python

I've considered changing the name of the package to my_foobuilder, and having it include a meta-package called foobuilder which consists only of an __init__.py that imports everything from my_foobuilder. I could instruct new users to import my_foobuilder directly. Then I could begin to deprecate the foobuilder name. In the end this would result in the same amount of work as if I changed foobuilder to my_foobuilder now, since everyone needs to be served updates and the foobuilder name can't be in deprecation purgatory forever.

Debian

The Debian problem shouldn't be too hard to solve; I can change the debian package name to my_foobuilder but have it still install the same (conflicting) Python package. I could then set the my_foobuilder package to Conflict with foobuilder. It might require users to fiddle around with their package manager to get things back on track during the transition but I don't think that's a big deal. Still, this prevents users from using the public foobuilder package at the same time.

Question

Is there an easier or better way to treat this situation than what I've considered above? Are there any problems with the solutions I'm considering? How would you deal with this?

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

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

发布评论

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

评论(3

少跟Wǒ拽 2024-11-25 21:43:38

我会发送电子邮件给新的 foobuilder 包作者来讨论这个问题。显然,你们中的一个人需要更改包名称;由于程序的专有性质,可能不希望更改其名称...向新包作者提出这个问题可能会提出一些新的解决方案。

确实没有明智的方法让 Python 以某种方式处理这个问题,因此“import foobuilder”可能意味着两件事。

I'd email the new foobuilder package author to discuss the problem. Obviously one of you needs to change package name; due to proprietary nature of your program is may be undesirable to change its name... Asking this question to the new package author may come up with some new solutions.

There really is no sane way to have Python handle this in a way so 'import foobuilder' can mean 2 things.

仅此而已 2024-11-25 21:43:38

我认为只要控制住了拼凑,在这里使用拼凑就可以了。如果我处于您的情况,我会创建一个带有包的其他标识符的文件,例如 so.py 并使其内容为

import relative_pathname/foobuilder as my_foobuilder

然后可以将包明确地引用为 so.my_foobuilder ,而不需要团队更改产品名称。这不是一个很好的解决方案,因为所有内部结构都需要改变,但它应该可以解决冲突,而不需要更多的修复。

I think that using a kludge would be fine here as long as the kludge is controlled. If I were in your situation, I would create a file with some other identifier to your package such as so.py and have the contents be

import relative_pathname/foobuilder as my_foobuilder

Then the package can be referenced as so.my_foobuilder unambiguously without requiring either team to change their product name. It is not a great solution, since all internals would need to be shifted, but it should resolve the conflict without requiring more of a fix.

不醒的梦 2024-11-25 21:43:38

符号链接?

$ echo "print 'foo'" > foo.py
$ ln -s foo.py bar.py
$ python -c "import foo; import bar"
foo
foo

非常简单,尽管有点黑客:)

Symlinks?

$ echo "print 'foo'" > foo.py
$ ln -s foo.py bar.py
$ python -c "import foo; import bar"
foo
foo

Very simple, albeit kind of hackish :)

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