在我的 python 项目中使用自定义包

发布于 2024-09-29 21:08:52 字数 459 浏览 2 评论 0原文

我现在正在用 python 做一些项目,我正在尝试弄清楚如何使用我自己的现有开源包版本。

例如,我将tipfy与zc.buildout一起使用,并添加到“paypal”包中。不幸的是它没有我需要的功能,所以我在 github 上分叉了它并添加了该功能。我将向原始包维护者发送拉取请求,但无论他们是否接受我的添加,我都想使用我的包版本并保持 zc.buildout 管理我的依赖项的便利性。我该怎么做?

我是否要将我自己对库的看法上传到 PyPI 并用我的名字作为前缀?这不会不必要地污染索引吗?

或者我应该创建并维护自己的索引和包存储库?我在哪里可以找到该格式?使用同名的修改包来托管我自己的存储库是否违反 OSS 许可证的条款? (我不想用新的命名空间修改项目中的每个文件)

我确信这个问题经常出现,而不仅仅是 python。我也可以在 Maven 和 SBT 中看到这种情况的发生...当人们想要使用自己版本的流行软件包时通常会做什么?

I'm doing a few projects in python right now, and I'm trying to figure out how to work with my own versions of existing open source packages.

For instance, I'm using tipfy with zc.buildout, and I've added in the 'paypal' package. Unfortunately it doesn't have a feature I need, so I've forked it on github and added the feature. I will send the original package maintainers a pull request, but whether they accept my additions or not, I'd like to use my version of the package and keep the convenience of having zc.buildout manage my dependencies. How do I do this?

Do I upload my own take on the library to PyPI and prefix it with my name? Wouldn't that unnecessarily pollute the index?

Or should I make and maintain my own index and package repo? Where do I find the format for this? And is it against to terms of the OSS licenses to host my own repo with modified packages with the same names? (I'd rather not modify every file in the project with new namespaces)

I'm sure this problem comes up quite a lot, and not just with python. I can see this happening with Maven and SBT, too... what do people usually do when they want to use their own versions of popular packages?

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

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

发布评论

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

评论(6

自演自醉 2024-10-06 21:08:57

将首先搜索您在项目的 setup.py 中放入 dependency_links 的任何路径。因此,只需将包放在一个路径中并将 dependency_links 设置为该路径即可。

local_packages = ['file:///path/to/packages']

setup(
 ...
 dependency_links=local_packages,
...)

Setuptool 文档详细介绍了如何操作这一切都有效,但这就是它的全部内容。

编辑:
zc.buildout 默认使用 setuptools dependency_links var。 如果你想关闭它

Any paths you put in dependency_links in setup.py of your project will be searched first. So just drop your package in a path and set dependency_links to that path.

local_packages = ['file:///path/to/packages']

setup(
 ...
 dependency_links=local_packages,
...)

Setuptool docs cover a little bit more on how it all works, but that's really all there is to it.

Edit:
zc.buildout uses the setuptools dependency_links var by default. If you want to turn it off.

你的往事 2024-10-06 21:08:57

我是否要将我自己对库的看法上传到 PyPI 并用我的名字作为前缀?

不。

这不会不必要地污染索引吗?

明显地。 (此外,您假设您的扩展实际上对其他人有用。除了您之外,它可能对任何人都没有那么有用。事实上,您的扩展可能表明无法理解该包。)

或者我应该创建并维护自己的索引和包存储库?

绝不。这完全是愚蠢的。您有修改后的包。除非您要针对 PyPI 完成,否则不需要存储库。你可以尝试,但为什么要麻烦呢?


这就是你要做的。

扩展

您可以轻松扩展给定的包,而无需修改或分叉。

my_paypal.py

from paypal import *

class MyFancyExtension( SomeExistingClass ):
    def override( self, ... )

def my_other_extension( ... ):
    this()
    that()

这很简单。它通常比分叉更好,因为您可以保留原始包而不受扩展的影响。

Do I upload my own take on the library to PyPI and prefix it with my name?

No.

Wouldn't that unnecessarily pollute the index?

Obviously. (Also, you're assuming that your extension is actually useful to others. It might not be all that useful to anyone but you. Indeed, your extension might indicate a failure to understand the package.)

Or should I make and maintain my own index and package repo?

Never. That's completely silly. You have the modified package. You don't need a repository unless you're going to complete against PyPI. You could try, but why bother?


Here's what you do.

extend

You can easily extend a given package without modifying or forking.

my_paypal.py

from paypal import *

class MyFancyExtension( SomeExistingClass ):
    def override( self, ... )

def my_other_extension( ... ):
    this()
    that()

It's quite easy. It's often better than forking because you preserve the original package untouched by your extensions.

海夕 2024-10-06 21:08:57

为您的专有、私有、分叉或开发包拥有自己的自定义 PyPI 服务器是非常有意义的。

例如 pypiserver 是轻量级且易于设置的。

It makes perfect sense to have your own custom PyPI server for your proprietary, private, forked or development packages.

For example pypiserver is lightweight and easy to set up.

月下客 2024-10-06 21:08:56

为了控制您的头痛,我真的建议您将所有此类自定义代码与您的包捆绑在一起。假设您对某个进行了分叉。只要其许可证允许,我就会将 package 的修改版本与我的代码捆绑在一起,就好像它只是另一个目录一样。您可以将其本地放置在 package 下,以便轻松找到它。一旦 package 的开发人员修复了您所需要的内容,只需删除此目录并使其再次依赖于在线包即可。

这种方法的另一个好处是使向用户/客户的分发变得更容易。

To keep your headache in check, I would really recommend just bundling all such custom code with your package. Say you made a fork of some package. As long as its license allows it, I would just bundle the modified version of package with my code, as if it's just another directory. You can place it locally under package so it will be easily found. Once the developers of package fix what you need, just remove this directory and make it a dependency on an online package once again.

An added bonus of this approach is making distribution to users/customers easier.

云之铃。 2024-10-06 21:08:56

我已经有一段时间没有使用 buildout 了,但如果我没记错的话,有一个 pip 配方允许您使用 pip 需求文件。您可以创建一个包含如下内容的需求文件:

-e git+http://<github url>

这将在安装时在本地检出软件包。

It's been a while since I've used buildout, but if I recall correctly, there is a pip recipe that allows you to use pip requirements files. You can create a requirements file that contains something like this:

-e git+http://<github url>

That will check the package out locally when installing.

紧拥背影 2024-10-06 21:08:55

有两种方法可以解决这个问题。我使用两者,具体取决于构建所使用的上下文:

  1. 使用 mr.developer< /a> 包含来自版本控制系统的软件包(mr.developer 支持多种系统,包括 git)。我在开发时使用它。

  2. 构建私有包存储库。 Apache 中的简单目录列表就足够了。将 URL 作为 find-links 条目添加到您的私有存储库:

    <前><代码>[构建]
    ...
    查找链接=
    ...
    http://用户名:[电子邮件受保护]/项目名称

    在此示例中,我还包含了用户名和密码(构建后将进行身份验证)以及服务器上特定于项目的路径。当然,您也可以为所有项目构建一个大型私有存储库。

    在该存储库中,您可以放置​​完整的鸡蛋,也可以仅放置包的 tarball。在 PyPI 之前搜索 find-links 中命名的存储库。

    我使用此方法进行部署扩展。这样软件将使用已发布的包,这使得发布管理更加清晰和简单。

托管您自己的 OSS 软件包分支是完全没问题的!这是使用 OSS 时获得的自由之一。请注意,当您像这样分叉 GPL 代码并将其分发给第三方时,您需要让他们可以使用您的更改。包存储库是实现这一点的一种方法。

There are two ways you could go about this. I use both, depending on the context the buildout is being used for:

  1. Use mr.developer to include packages from a version control system (mr.developer support a wide range of systems, including git). I use this when developing.

  2. Build a private package repository. A simple directory listing in Apache is enough. Add the URL to your private repository as a find-links entry:

    [buildout]
    ...
    find-links =
        ...
        http://username:[email protected]/projectname
    

    In this example I also included a username and password (buildout then will authenticate) and a path on the server that is project specific. You can also just build one big private repository for all your projects, of course.

    In that repository you either put complete eggs, or just a tarball of the package. Repositories named in find-links are searched before PyPI.

    I use this method for deployment buildouts. This way the software will use released packages, which makes release management much clearer and simpler.

Hosting your own forks of OSS packages is perfectly fine! This is one of the freedoms you get when using OSS. Note that when you fork GPL code like this, and are distributing it to a third party, you need to make your changes available to them. A package repository is one way of doing complying with this.

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