当使用pbr时如何将git仓库作为依赖项包含进来

6
我正在使用pbr,它使用requirements.txt文件查找依赖项。
我在requirements.txt中有一行,如下所示:git+ssh://git@github.com/user/repo.git。当我运行pip install -r requirements.txt时,它可以正常工作。
但是,当我运行python setup.py build时,遇到了错误:
error in setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'+ssh://g'"

有很多Stack Overflow的答案专门处理使用setuptools时的这个问题,它们都建议将Git依赖项放入setup.py中的dependency_links列表中。

我希望pbr能够直接从requirements.txt中处理我的Git依赖项,这种方式可以在我运行python setup.py buildpip install -r requirements.txt时正常工作。

这是否可能?是否有任何接近的解决方案?

1个回答

2
在您提供的示例中,pbr正在将整行传播到install_requires,这会产生无效的行。
通过#egg=name提供要求名称
为了使其按预期工作,该URL需要一个#egg后缀,以告诉pbr该URL提供了什么要求。 如果URL看起来像这样,pbr将从#egg部分scrape a requirement并仅将repo传播到install_requires:
git+ssh://git@github.com/user/repo.git#egg=repo

版本约束

如果包含版本号,pbr 将在其上添加一个 >= 约束条件。因此,在 install_requires 中,这将变为 repo>=1.2.3

git+ssh://git@github.com/user/repo.git#egg=repo-1.2.3

依赖链接

它还将提取包含完整URL的dependency_link项。您可以通过将--process-dependency-links传递给pip来使用它。默认情况下,除非该软件包也可通过PyPI获得,否则pip将返回错误Could not find a version that satisfies the requirement repo。如果指定了--process-dependency-links,则会从Git URL中获取它。

使用-e标志,或要求pbr>=1.9.0

在1.9.0版本之前,pbr只识别httphttps的URL,除非该行以-e开头。它在this commit中添加了对git://git+ssh://git+https://的支持,不需要-e

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接