[英]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.