[英]Python setup.py develop stuck at “writing dependency_links”
[英]Python setup.py with private repository on GitLab as dependency_links based on commit ID
我正在尝试安装一个私有依赖项(不是 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
setup.py
时是否使用git
命令?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 .
时才有效pip install .
在包含setup.py
的目录中。 这不适用于python setup.py install --record installed_files.txt
。
https://python-packaging.readthedocs.io/已经很旧而且过时了。 它的来源最后一次更新是在 2016 年 12 月 29 日,其中大部分内容自 2012 年以来没有更新。自那时以来,Python 包装格局发生了重大变化。 新文档位于https://packaging.python.org/
dependency_links
被声明为过时并最终在pip
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-specifiers和https://www.python.org/dev/peps/pep-0440/#direct-references
这需要pip install
包括pip install .
并且不适用于python setup.py install
。
我已经阅读了多个答案,但只有这个对我有用(使用pip 20.2.3
和Gitlab 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.