在setup.py中,extras_require的依赖关系链接

10
  1. Is there a way to process dependency links automatically when installing a package with extras, without having to call --process-dependency-links as it is the case with install_requires?

    pip install -e .[extra] --process-dependency-links
    

    I need this because the dependency is only located on a private git repo.

  2. Is it possible to install extras using python setup.py install?

  3. Is --process-dependency-links still to be considered as it is deprecated? I am not sure about the status here.


你最终解决了这个问题吗? - chishaku
@chishaku 不是很确定... 但是随着pyproj.toml的最新进展和新版pip的推出,我们可能会有些好运! - tupui
1
我想我确实做到了。我会添加一个答案。 - chishaku
2个回答

6

我花了太长时间来研究如何使用setup.cfg完成这个任务,希望这篇文章能够帮助到其他人,因为原帖并没有指定要使用setup.py。我还包括了一个自定义URL用于install_requires,因为我也花了一段时间才弄清楚。

#setup.cfg (only showing relevant parts)
[options]
install_requires =
    pyyaml @ git+https://github.com/yaml/pyyaml.git@master
    
[options.extras_require]
jsonschema = jsonschema @ git+https://github.com/Julian/jsonschema.git@v3.2.0
six = six
  1. pip install -e .[jsonschema]将为您获取一个自定义URL的额外内容,或者pip install -e .[jsonschema,six]将同时获取两个额外内容(请注意,在附加项列表中的.后面没有空格或逗号周围没有空格)。
  2. 据我所知,您无法使用python setup.py install安装额外的依赖项。
  3. 是的,尽管有很多抱怨,但--process-dependency-links仍然被弃用,但一旦您知道语法,上述方法就足够好了。

1
  1. 如果您使用 extras_require,则不再需要使用 --process-dependency-links

已测试使用 pip 版本 19.3.1

示例:

$ pip install -e .[graphs]

# setup.py  

from setuptools import setup
setup(
    name='myservice',
    version='0.1.0',
    install_requires=[
        'requests',
    ],
    extras_require={
        'graphs': [
            'graphcommons @ git+ssh://git@github.com/graphcommons/graphcommons-python@master',
        ],
    },
)


通过使用ssh协议(而不是https)访问git存储库,您可以从私有存储库中安装。
2. 不确定 python setup.py install ,但 pip install .[extras] 应该足够好?
3. 是的,在pip版本19中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接