Python GitLab上带有私有存储库的setup.py作为基于提交ID的dependency_links

我正在尝试安装一个私有依赖项(不是Python在pypI上可以找到的东西)。

我已经在文件setup.py中添加了此文件(如此处说明: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之后使用@听起来是合理的(因为这是通过其他多种语言完成的,依赖管理工具)。

执行命令python setup.py install时,我会在日志/输出中看到以下内容:

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

但是然后我没有看到该软件包实际上已安装,因为从日志/输出中可以看到其他依赖项。

我知道git命令中有有效的GitLab访问令牌设置,因为我已经运行了以下命令:

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

,当我使用以下命令检查git配置时可以看到它:

git config --list | grep gitlab
url.https://<accESS_TOKEN_NAME>:<accESS_TOKEN_VALUE>@gitlab.com.insteadof=https://gitlab.com
  • Python在运行git时是否使用setup.py命令?
  • 如何在Python setup.py文件中指定私有GitLab依赖关系? 它应基于提交ID而非软件包版本
  • 上面有什么问题?
  • 我还感觉到,在使用pip install和定位setup.py而不是运行python setup.py install时,这可能会以不同的方式运行,是否有一种独特的方法可以同时使用两种Python装置?我之所以这样问是因为,在摆弄dependency_links时我尝试使用git+ssh之类的东西来代替https和其他变化,所有这些人都没有安装带有各种日志/输出的私有存储库找不到该存储库。

修改

我避免使用dependency_links,因为它似乎已弃用,因此我将答案中提出的解决方案用于:

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时,安装失败,并显示以下消息:

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

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

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

bbcwch123 回答:Python GitLab上带有私有存储库的setup.py作为基于提交ID的dependency_links

https://python-packaging.readthedocs.io/很老,已经过时了。它的来源是last updated,于2016年12月29日发布,其大部分内容自2012年以来未进行更新。新文档位于https://packaging.python.org/

dependency_links被宣布作废,最后removedpip 19.0中被宣布。替换为具有特殊语法的install_requires(自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-specifiershttps://www.python.org/dev/peps/pep-0440/#direct-references

这需要pip install包括pip install .,并且不能与python setup.py install一起使用。

,

我已经阅读了多个答案,但是只有一个答案对我有用(使用pip 20.2.3Gitlab Pypi功能):

pip3 install --extra-index-url https://__token__:my_personal_token@gitlab.com/api/v4/projects/347/packages/pypi/simple .

我的setup.py如下:

from setuptools import setup

setup(name='whatever_production_scripts',version='0.0.1',description='Whatever production scripts',url='https://gitlab.com/user/whatever',author='Me Myself',author_email='user@whatever.com',license='All rights reserved',scripts=[
          'whatever_production_scripts/production/insomnia.py','whatever_production_scripts/production/rdsmaintenance.py','whatever_production_scripts/production/changeinstancetype.py',],packages=[
          'whatever_production_scripts','whatever_production_scripts.production',classifiers=[
          "Development Status :: 3 - Alpha","Intended Audience :: System Administrators","Operating System :: POSIX :: Linux","Topic :: Internet","Topic :: System :: Systems Administration","Programming Language :: Python :: 3 :: Only"
      ],install_requires=[
          'privatepackage1>=0.1','publicpackage1>=7','publicpackage2>=2'
      ],zip_safe=False)
本文链接:https://www.f2er.com/3005792.html

大家都在问