如何将 setup.py/install_requires 中的值与 Pipfile/packages 同步 [英] How do I sync values in setup.py / install_requires with Pipfile / packages

查看:81
本文介绍了如何将 setup.py/install_requires 中的值与 Pipfile/packages 同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在一个同时使用 setup.pyPipfile 的项目中工作,您通常会在以下位置找到相同的值:Pipfile/[packages]setup.py/install_requires.

If you work on a project that uses both setup.py and Pipfile you often find the same values in: Pipfile/[packages] and setup.py/install_requires.

有谁知道我如何告诉 Pipfilesetup.py/install_requires 中的值用于 [packages]?

Does anyone know how I can tell Pipfile to use values from setup.py/install_requires for [packages]?

推荐答案

在你的 setup.py 中:

  1. 定义一个函数来读取一个部分:

  1. Define a function to read a section:

def locked_requirements(section):
"""Look through the 'Pipfile.lock' to fetch requirements by section."""
    with open('Pipfile.lock') as pip_file:
        pipfile_json = json.load(pip_file)

    if section not in pipfile_json:
        print("{0} section missing from Pipfile.lock".format(section))
        return []

    return [package + detail.get('version', "")
            for package, detail in pipfile_json[section].items()]

  • setup 函数中返回 default 部分的列表:

  • Within the setup function return the list from the default section:

    setup(
        # ...snip...
        install_requires=locked_requirements('default'),
        # ...snip...
    )
    

  • 重要说明:在 MANIFEST.in 中包含 Pipfile.lock,例如:

    include Pipfile.lock
    

    这篇关于如何将 setup.py/install_requires 中的值与 Pipfile/packages 同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆