gpt4 book ai didi

python - setuptools 应该在 setup.cfg 文件的 setup_requires 条目中吗?

转载 作者:太空宇宙 更新时间:2023-11-03 14:35:57 25 4
gpt4 key购买 nike

importlib_resources Python < 3.7 的 importlib.resources 的反向移植标准库模块在 setup.cfg 文件中有以下部分:

[options]
python_requires = >=2.7,!=3.0,!=3.1,!=3.2,!=3.3
setup_requires =
setuptools
wheel
install_requires =
pathlib2; python_version < '3'
typing; python_version < '3.5'
packages = find:

为什么 setup_requires 包含 setuptools?这似乎没有意义,因为:

  • setup.py 文件的第一行导入setuptools,所以在调用setup 函数时读取setup.cfg 文件指示要安装 setuptools 安装 setuptools 已经太迟了:

    from setuptools import setup
    setup()
  • setuptools 已经安装在任何全新的 Python 安装上(好吧,仅在 Windows 10 和 MacOS 10.15 上使用 Python 3.8.0 进行了测试):

    $ python -V
    Python 3.8.0
    $ pip list
    Package Version
    ---------- -------
    pip 19.2.3
    setuptools 41.2.0
    WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.

最佳答案

不,根据 PEP 518setuptools 不应包含在 setup_requires 中(大胆强调我的):

Setuptools tried to solve this with a setup_requires argument to its setup() function [3]. This solution has a number of issues, such as:

  • No tooling (besides setuptools itself) can access this information without executing the setup.py, but setup.py can't be executed without having these items installed.
  • While setuptools itself will install anything listed in this, they won't be installed until during the execution of the setup() function, which means that the only way to actually use anything added here is through increasingly complex machinations that delay the import and usage of these modules until later on in the execution of the setup() function.
  • This cannot include setuptools itself nor can it include a replacement to setuptools, which means that projects such as numpy.distutils are largely incapable of utilizing it and projects cannot take advantage of newer setuptools features until their users naturally upgrade the version of setuptools to a newer one.
  • The items listed in setup_requires get implicitly installed whenever you execute the setup.py but one of the common ways that the setup.py is executed is via another tool, such as pip, who is already managing dependencies. This means that a command like pip install spam might end up having both pip and setuptools downloading and installing packages and end users needing to configure both tools (and for setuptools without being in control of the invocation) to change settings like which repository it installs from. It also means that users need to be aware of the discovery rules for both tools, as one may support different package formats or determine the latest version differently.

关于python - setuptools 应该在 setup.cfg 文件的 setup_requires 条目中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58521386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com