Python 包是否可以依赖于另一个 Python 包的特定版本控制修订版?

发布于 2024-08-17 21:15:51 字数 168 浏览 5 评论 0原文

一些有用的 Python 包在 pypi 上被破坏,唯一可接受的版本是版本控制系统中的特定版本。可以用 setup.py 来表达,例如

requires = 'svn://example.org/useful.package/trunk@1234' 吗?

Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g

requires = 'svn://example.org/useful.package/trunk@1234' ?

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

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

发布评论

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

评论(4

讽刺将军 2024-08-24 21:15:51

你需要做两件事。首先,需要您想要的确切版本,例如:

install_requires = "useful.package==1.9dev-r1234"

然后包含 dependency_links 设置,指定在哪里找到它:

dependency_links = ["svn://example.org/useful.package/trunk@1234#egg=useful.package-1.9dev-r1234"]

请注意 的版本 #egg= 部分dependency_links URL 必须完全匹配您在 install_requires 中指定的内容;这就是将这两部分联系在一起的原因。

发生的情况是,setuptools 会看到链接上的 #egg 标记,并将该 URL 保存为该包的精确版本的可用下载 URL。然后,当它稍后尝试解决该要求时,它应该下载该精确的 SVN URL。

(但是请注意,要使其真正起作用,目标 SVN 修订版必须实际构建具有该名称和版本的 Egg。否则,您的依赖项将在运行时失败!所以,这实际上只能起作用如果您所依赖的包在其默认构建版本号中使用 SVN 修订标签。)

You need to do two things. First, require the exact version you want, e.g.:

install_requires = "useful.package==1.9dev-r1234"

and then include a dependency_links setting specifying where to find it:

dependency_links = ["svn://example.org/useful.package/trunk@1234#egg=useful.package-1.9dev-r1234"]

Note that the version #egg= part of the dependency_links URL must exactly match what you specified in install_requires; this is what links the two pieces together.

What happens is that setuptools sees the #egg tag on the link and saves the URL as an available download URL for that precise version of the package. Then, when it tries to resolve that requirement later, it should download that precise SVN URL.

(Note, however, that for this to really work, the targeted SVN revision has to actually build an egg with that name and version. Otherwise, your dependency will fail at runtime! So, this really only works if the package you're depending on uses SVN revision tags in their default build version numbers.)

对你再特殊 2024-08-24 21:15:51

如果您确实需要另一个软件包的模糊版本,并且无法使用其他版本,那么您可能只想简单地将该版本的软件包与您自己的软件包一起分发。如有必要,请将其放在您自己的命名空间中,以确保您的版本是所使用的版本。

If you really require an obscure version of another package, and there's no way to make do with other versions, you might want to simply distribute that version of the package with your own. If necessary put it in your own namespace to ensure that your version is the one that is used.

任谁 2024-08-24 21:15:51

我还没有弄清楚如何从 setup.py 引用它,但 pip 可以使用简单的需求文件检查 Python 包的特定修订版。使用名为 requires.txt 的需求文件,pip install -r require.txt 将安装该文件中列出的所有软件包(及其依赖项)。

这是我的需求文件的一部分。以 -e 开头的行从版本控制(git、svn 或 Mercurial)中检查包的特定修订(包括我的项目),并以可编辑的形式安装它们。 pip freeze 以此格式列出所有已安装的软件包。

requires.txt

-e hg+file:///home/me/my-private-project#egg=myproject
-e hg+http://bitbucket.org/ianb/webob@tip#egg=WebOb
-e svn+http://svn.sqlalchemy.org/sqlalchemy/trunk@6638#egg=SQLAlchemy
-e svn+http://svn.zope.org/repos/main/z3c.saconfig/trunk@106508#egg=z3c.saconfig
## The following requirements were added by pip --freeze:
APScheduler==1.01
simplejson==2.0.9
... (many more)

I haven't figured out how to reference this from setup.py but pip can check out specific revisions of Python packages with a simple requirements file. With a requirements file called requires.txt, pip install -r requires.txt will install all the packages listed in that file (and their dependencies).

Here is part of my requirements file. The lines starting with -e check out specific revisions of packages from version control (git, svn, or mercurial), including my project, and install them in an editable form. pip freeze lists all installed packages in this format.

requires.txt:

-e hg+file:///home/me/my-private-project#egg=myproject
-e hg+http://bitbucket.org/ianb/webob@tip#egg=WebOb
-e svn+http://svn.sqlalchemy.org/sqlalchemy/trunk@6638#egg=SQLAlchemy
-e svn+http://svn.zope.org/repos/main/z3c.saconfig/trunk@106508#egg=z3c.saconfig
## The following requirements were added by pip --freeze:
APScheduler==1.01
simplejson==2.0.9
... (many more)
就像说晚安 2024-08-24 21:15:51

您可以发布特定版本的软件包,但必须将它们一起分发。无法使用标准 Python 自动下载它们。

但是,您可以使用 Buildout 并创建一个 buildout.cfg 来复制环境。如果您使用 mr.developer 等扩展,它可以检查并安装特定修订版。

http://pypi.python.org/pypi/zc.buildout
http://pypi.python.org/pypi/mr.developer

You can release packages of specific versions, but you have to distribute them together. There is no way to automatically download them with standard Python.

However, you can use Buildout and create a buildout.cfg that makes it possible to replicate the environment. It can check out and install specific revisions if you use extensions like mr.developer.

http://pypi.python.org/pypi/zc.buildout
http://pypi.python.org/pypi/mr.developer

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