简体   繁体   English

pip3 setup.py install_requires私人仓库的PEP 508 git URL

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

I am trying to run: 我想跑:

pip3 install -e .

in my Python project where I have the following setup.py : 在我的Python项目中,我有以下setup.py

from setuptools import setup

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

but it fails with: 但它失败了:

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

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. 我猜我的URL格式是正确的,因为PEP 508不允许为ssh克隆URL指定git用户名。

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)? 对于私有git存储库(在这种情况下托管在BitBucket上)的install_requires依赖关系,使用git + ssh协议的PEP 508 URL的正确语法是什么? What is the syntax for specifying a specific branch, tag or sha? 指定特定分支,标签或sha的语法是什么?

More context to avoid XY problem 更多上下文以避免XY问题

I have an internal Python project that depends on multiple internally developed Python packages. 我有一个内部Python项目,它依赖于多个内部开发的Python包。 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. 我想避免在组织中托管我自己的PIP存储库的必要性,因此我试图直接使用git URL。 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). 我需要对git URL使用ssh协议,因为所有用户都配置了ssh密钥,要求所有用户在BitBuckets中配置他们的应用密码会很麻烦(我需要2FA,常规用户密码不起作用) 。

I have already tried to use: 我已经尝试过使用:

dependency_links

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"
    ]
)

But they are deprecated and they are ignored by pip3 install -e . 但它们已被弃用, pip3 install -e .会忽略它们pip3 install -e . . According to documentation I've found, PEP 508 URLs should be used instead. 根据我发现的文档,应该使用PEP 508 URL。

requirements.txt file with entries duplicated from install_requires entries requirements.txt文件,其中的条目与install_requires条目重复

I have a requirements.txt file with: 我有一个requirements.txt文件:

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

and I use pip3 install -r requirements.txt instead of pip3 install -e . 我使用pip3 install -r requirements.txt而不是pip3 install -e . . It works but is suboptimal as I have to keep both setyp.py and requirements.txt in sync. 它工作但不是最理想的,因为我必须同时保持setyp.pyrequirements.txt

If there is any other recommended solution for my problem I would like to learn about it :) 如果我的问题有任何其他推荐的解决方案,我想了解它:)

After checking pip source code I found the correct syntax for private BitBucket repositories. 检查pip源代码后,我找到了私有BitBucket存储库的正确语法。

The general form for the packages with URLs is <package name>@<URI> and the URI must start with a <scheme>:// . 带有URL的包的一般形式是<package name>@<URI> ,URI必须以<scheme>://开头。

So I fixed it to: 所以我把它修复为:

anotherpackage@git+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命令(由pip调用)抱怨存储库URL ssh://git@bitbucket.org:myorg/anotherpackage.git

I checked the git documentation for the ssh:// URLs format and found out that hostname and organisation parts must be separated with / instead of : : 我检查了git文档中的ssh:// URLs格式,发现主机名和组织部分必须用/而不是:

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

This URL works fine. 此URL工作正常。 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 : 我还从pip源代码中了解到,可以通过附加@<rev-spec>来指定实际的版本/分支/标记,因此我可以在install_requires指定例如标记0.0.1和以下内容:

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

The only issue that I still have is that when I change the revision and run pip3 install -e . 我仍然唯一的问题是,当我更改修订版并运行pip3 install -e . again it doesn't detect the change (even when run with --upgrade ). 再次它不会检测到更改(即使使用--upgrade运行)。 I have to manually uninstall the package ( pip3 uninstall anotherpackage ) and run pip3 install -e . 我必须手动卸载软件包( pip3 uninstall anotherpackage )并运行pip3 install -e . again. 再次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM