簡體   English   中英

Python setup.py 與 GitLab 上的私有存儲庫作為基於提交 ID 的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
  • Python 在運行setup.py時是否使用git命令?
  • 如何在 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 .時才有效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-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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM