【问题标题】:Depend on git repository in setup.py依赖于 setup.py 中的 git 仓库
【发布时间】:2016-11-14 09:12:27
【问题描述】:

我正在尝试使项目依赖于 git 依赖项。但是,我似乎无法让它工作。我基本上想要实现的是以下,但它不起作用:

#!/usr/bin/env python3
from setuptools import setup


setup(
    name='spam',
    version='0.0.0',
    install_requires=[
        'git+https://github.com/remcohaszing/pywakeonlan.git'
    ])

我在上面尝试了几种变体,例如添加@master#egg=wakeonlan-0.2.2,但这并没有什么不同。

以下方法有效,但仅在使用已弃用的 pip 标志 --process-dependency-links 时有效:

#!/usr/bin/env python3
from setuptools import setup


setup(
    name='spam',
    version='0.0.0',
    install_requires=[
        'wakeonlan'
    ],
    dependency_links=[
        'git+https://github.com/remcohaszing/pywakeonlan.git#egg=wakeonlan-0.2.2'
    ])

这个输出:

$ pip install --no-index -e . --process-dependency-links
Obtaining file:///home/remco/Downloads/spam
  DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.
Collecting wakeonlan (from spam==0.0.0)
  Cloning https://github.com/remcohaszing/pywakeonlan.git to /tmp/pip-build-mkhpjcjf/wakeonlan
  DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.
Installing collected packages: wakeonlan, spam
  Running setup.py install for wakeonlan ... done
  Running setup.py develop for spam
Successfully installed spam wakeonlan-0.2.2

以下确实有效:

pip install 'git+https://github.com/remcohaszing/pywakeonlan.git'

在需求文件中添加 git url 也可以。

是否有任何不推荐使用的方式来使用 setup.py 文件来依赖 git url?

【问题讨论】:

  • 不,答案建议使用已弃用的dependency_links。
  • 一个相关的 github 问题:github.com/pypa/pip/issues/2023 - 但是我还没有看到解决方案。
  • 目前,似乎没有不推荐使用的方法:\

标签: python git pip setuptools


【解决方案1】:

Pip >= 9.1 (commit 6ec559) 将支持新的@ 语法,如PEP508 中所述,其格式为:pkgname@url#sum - 例如:

pip install --no-index packaging@https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl#sha256=ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4

这也可以在 setup.py 中以相同的方式使用,例如:

install_requires=['packaging@https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl#sha256=ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4']

您现在可以通过对pip master 的最新提交来尝试一下(以“错误”的方式更新 pip!):

$ pip install https://github.com/pypa/pip/archive/master.zip
$ pip install --no-index packaging@https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl#sha256=ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4
Collecting packaging@ https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl#sha256=ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4 
from https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl#sha256=ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4
Downloading https://files.pythonhosted.org/packages/2f/2b/c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/packaging-15.3-py2.py3-none-any.whl
Installing collected packages: packaging
Successfully installed packaging-15.3

【讨论】:

  • 似乎有这样的依赖关系会阻止上传到 PyPi。是否有计划允许这样做?
猜你喜欢
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 2015-12-17
相关资源
最近更新 更多