pip3 setup.py install_requires PEP 508 git URL for private repo [英] pip3 setup.py install_requires PEP 508 git URL for private repo

查看:79
本文介绍了pip3 setup.py install_requires PEP 508 git URL for private repo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行:

pip3 install -e.

在我的Python项目中,其中具有以下 setup.py :

in my Python project where I have the following setup.py:

from setuptools import setup

setup(
    name='mypackage',
    install_requires=[
        "anotherpackage@git+git@bitbucket.org:myorg/anotherpackage.git"
    ]
)

但是失败了:

error in mypackage setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid URL given

我想我的URL格式为 PEP 508 <是正确的/a>不允许为ssh克隆URL指定git用户名.

I guess it is correct about the format of my URL as PEP 508 doesn't allow specifying git user name for ssh clone URLs.

具有git + ssh协议的PEP 508 URL的正确语法是什么(对于私有git存储库,在本例中为BitBucket托管)的 install_requires 依赖关系?指定特定分支,标记或sha的语法是什么?

What is the correct syntax for PEP 508 URLs with git+ssh protocol for install_requires dependency for private git repositories (in this case hosted on BitBucket)? What is the syntax for specifying a specific branch, tag or sha?

我有一个内部Python项目,该项目依赖于多个内部开发的Python包.我想避免在组织中托管我自己的PIP存储库的必要,因此,我尝试直接使用git URL.我需要对git URL使用ssh协议,因为所有用户都已配置了他们的ssh密钥,要求所有用户在BitBuckets中配置其应用密码会很麻烦(我需要2FA,并且常规用户密码无效)

I have an internal Python project that depends on multiple internally developed Python packages. I would like to avoid the necessity for hosting my own PIP repository in the organisation and thus I am trying to use git URLs directly. I need to use ssh protocol for git URLs as all the users have their ssh keys configured and it would be cumbersome to ask all the users to configure their app passwords in BitBuckets (I have 2FA required and the regular user password doesn't work).

我已经尝试使用:

setup(
    name='mypackage',
    install_requires=[
        "anotherpackage==0.0.1"
    ],
    dependency_links=[
        "git+git@bitbucket.org:myorg/anotherpackage.git@0.0.1#egg=anotherpackage-0.0.1"
    ]
)

但是它们已被弃用,并且被 pip3 install -e.忽略.根据我发现的文档,应该改用PEP 508 URL.

But they are deprecated and they are ignored by pip3 install -e .. According to documentation I've found, PEP 508 URLs should be used instead.

我有一个 requirements.txt 文件,其内容为:

I have a requirements.txt file with:

-e git+git@bitbucket.org:myorg/anotherpackage.git@0.0.1#egg=anotherpackage

,我使用 pip3 install -r requirements.txt 而不是 pip3 install -e..它可以工作,但不是最佳选择,因为我必须同时同步 setyp.py requirements.txt .

and I use pip3 install -r requirements.txt instead of pip3 install -e .. It works but is suboptimal as I have to keep both setyp.py and requirements.txt in sync.

如果我的问题还有其他推荐的解决方案,我想了解一下:)

If there is any other recommended solution for my problem I would like to learn about it :)

推荐答案

检查 pip 源代码后,我发现了专用BitBucket存储库的正确语法.

After checking pip source code I found the correct syntax for private BitBucket repositories.

带有URL的软件包的一般形式为<软件包名称> @< URI> ,并且URI必须以< scheme>://开头

The general form for the packages with URLs is <package name>@<URI> and the URI must start with a <scheme>://.

所以我将其固定为:

anotherpackage @ git + ssh://git@bitbucket.org:myorg/anotherpackage.git

然后我遇到了另一个错误-这次 git 命令(由 pip 调用)抱怨存储库URL ssh://git @ bitbucket.org:myorg/anotherpackage.git .

and then I was getting a different error - this time git command (invoked by pip) was complaining about repository URL ssh://git@bitbucket.org:myorg/anotherpackage.git.

我检查了git文档中的 ssh:// URL格式,发现主机名和组织部分必须用/而不是::

I checked the git documentation for the ssh:// URLs format and found out that hostname and organisation parts must be separated with / instead of ::

ssh://git@bitbucket.org/myorg/anotherpackage.git

此URL可以正常工作.我还从 pip 源代码中了解到,可以通过附加 @< rev-spec> 来指定实际的修订/分支/标记,因此我可以指定例如标记 0.0.1 ,在 install_requires 中具有以下内容:

This URL works fine. I also learned from the pip source code that the actual revision/branch/tag can be specified by appending @<rev-spec> so I can specify for example the tag 0.0.1 with the following in install_requires:

anotherpackage @ git + ssh://git@bitbucket.org:myorg/anotherpackage.git@0.0.1

我唯一仍然遇到的问题是,当我更改修订版本并运行 pip3 install -e 时,它仍然无法检测到更改(即使使用-upgrade运行时也是如此)).我必须手动卸载程序包( pip3卸载另一个程序包),然后再次运行 pip3 install -e..

The only issue that I still have is that when I change the revision and run pip3 install -e . again it doesn't detect the change (even when run with --upgrade). I have to manually uninstall the package (pip3 uninstall anotherpackage) and run pip3 install -e . again.

这篇关于pip3 setup.py install_requires PEP 508 git URL for private repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆