Python setup.py,在GitLab上具有私有存储库,并根据提交ID作为依赖关系链接 [英] Python setup.py with private repository on GitLab as dependency_links based on commit ID

查看:195
本文介绍了Python setup.py,在GitLab上具有私有存储库,并根据提交ID作为依赖关系链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装私有依赖项(Python无法在PyPI上找到它)。

I am trying to install a private dependency (not something that Python could find on PyPI).

我已将文件添加到文件 setup中.py 这个(如此处所述: https://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi ):

I have added to the file setup.py this (as explained here: https://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi):

dependency_links = [
        'https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>'
      ]

在该官方文档中,他们并没有真正详细解释什么是该URL的格式,但是在 @ 之后使用< COMMIT_ID 听起来是合理的(因为它以多种方式其他语言和依赖项管理工具。)

On that official documentation they don't really explain in details what's the format of that URL, however using a <COMMIT_ID after the @ sounds reasonable (as it's done in a variety of other languages and dependency management tools).

执行命令 python setup.py install 时,我会在罗gs /输出以下内容:

When executing the command python setup.py install then I see in the logs/output this:

Reading https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>

但是从日志/输出中我看不到实际安装的软件包

but then I don't see that package being actually installed as I can see from the logs/output for other dependencies.

我知道我的 git 命令有一个有效的GitLab访问令牌设置,因为我ve运行以下命令:

I know there is a valid GitLab access token setup for my git command, because I've run this:

git config \
      --global \
      url."https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com".insteadOf \
      "https://gitlab.com"

,当我检查 git 配置时,可以看到它:

and I can see it when checking the git config with:

git config --list | grep gitlab
url.https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com.insteadof=https://gitlab.com




  • 运行设置时,Python是否使用 git 命令。 py

  • 如何在Python setup.py 文件中指定私有GitLab依赖关系? 它应该基于提交ID而不是程序包版本

  • 上面有什么问题?

  • 我有当使用 pip install 并定位 setup.py 而不是运行<$ c $时,感觉运行可能会有所不同c> python setup.py install ,是否有使这两种Python安装都可以使用的独特方法?我之所以这样问是因为,当我摆弄 dependency_links 时,我尝试的是诸如 git + ssh 之类的东西,而不是 https 和其他变体,所有这些都无法安装具有各种日志/输出的私有存储库,并显示未找到该存储库。

    • Is Python using the git command when running setup.py?
    • How can I specify a private GitLab dependency inside a Python setup.py file? It should be based on a commit ID rather than a package version
    • What's wrong with the above?
    • I have also the feeling this may be running differently when using pip install and targeting setup.py instead of running python setup.py install, is there a unique way of making this work with both flavors of Python installations? I am asking this because when fiddling with dependency_links I was trying various things like git+ssh instead of https and other variations, all of them failing to install that private repository with various log/outputs saying that repository was not found.
    • 编辑

      我避免了 dependency_links ,因为似乎已弃用,因此我使用了答案中建议的解决方案:

      I've avoided dependency_links because it seems deprecated, so I used the solution proposed in the answer as:

      install_requires=[
          ...
          "mylibraryname @ git+https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>",
          ...
      ],
      

      但是执行 python setup.py install时--record installed_files.txt ,然后安装失败,并显示以下消息:

      However when executing python setup.py install --record installed_files.txt, then the installation fails with this message:

      Searching for mylibraryname@ git+https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>
      Reading https://pypi.org/simple/mylibraryname/
      Couldn't find index page for 'mylibraryname' (maybe misspelled?)
      Scanning index of all packages (this may take a while)
      Reading https://pypi.org/simple/
      No local packages or working download links found for mylibraryname@ git+https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>
      error: Could not find suitable distribution for Requirement.parse('mylibraryname@ git+https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>')
      

      所以我尝试使用 pip install。 假设当前目录中有一个 setup.py 文件,此方法有效:

      So I tried to use pip install . assuming there is a setup.py file in the current directory, this worked:

      Collecting mylibraryname@ git+https://<ACCESS_TOKEN_NAME>:<ACCESS_TOKEN_VALUE>@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID> from git+https://<ACCESS_TOKEN_NAME>:****@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID> (from <MY_LIBRARY_WITH_SETUP_PY>==<MY_LIBRARY_VERSION>)
        Cloning https://<ACCESS_TOKEN_NAME>:****@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git (to revision <COMMIT_ID>) to /tmp/pip-install-bakazwe2/mylibraryname
        Running command git clone -q https://<ACCESS_TOKEN_NAME>:sYzRKNsYAnv5GtS6zLZj@gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git /tmp/pip-install-bakazwe2/mylibraryname
      

      此解决方案似乎仅有效在包含 setup.py 的目录中使用 pip install。时。这不适用于 python setup.py install --record installed_files.txt

      This solution seems to work only when using pip install . in a directory containing setup.py. This does not work with python setup.py install --record installed_files.txt.

      推荐答案

      https://python-packaging.readthedocs.io/ 很老,而且过时的。其来源是最后更新,日期为2016年12月29日,其中大部分是自2012年以来未更新。自那时以来,Python包装格局发生了重大变化。新文档位于 https://packaging.python.org/

      https://python-packaging.readthedocs.io/ is quite old and outdated. Its sources was last updated at Dec 29, 2016 and most parts of it were not updated since 2012. Python packaging landscape changed significantly since that times. The new docs are at https://packaging.python.org/

      dependency_links 被宣布作废,最后已删除 pip 19.0中。替换为具有特殊语法的 install_requires (自 pip 19.1开始受支持):

      dependency_links were declared obsolete and finally removed in pip 19.0. The replacement for it is install_requires with special syntax (supported since pip 19.1):

      install_requires=[
          'package_name @ git+https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>'
      ]
      

      请参见 https://pip.readthedocs.io/en/stable/reference/pip_install/#requirement-specifiers https://www.python.org/dev/peps/pep -0440 /#direct-references

      这需要 pip安装,其中包括 pip install。,不适用于 python setup.py install

      This requires pip install including pip install . and doesn't work with python setup.py install.

      这篇关于Python setup.py,在GitLab上具有私有存储库,并根据提交ID作为依赖关系链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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