setuptools 应该在 setup.cfg 文件的 setup_requires 条目中吗?
Should setuptools be in the setup_requires entry of setup.cfg files?
importlib_resources
backport for Python < 3.7 of the 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.
Why does setup_requires includes setuptools? This does not seem to make sense
完全没有意义。另一方面,它不会妨碍任何事情,为什么不呢?
不,setuptools
不应包含在 setup_requires
中,根据 PEP 518(粗体强调我的):
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.
接受的答案大部分是正确的,但 PEP 518 说的是。
[The setup_requires
mechanism] cannot include setuptools
itself...
它在技术上是不正确的,正如 importlib_resources
所证明的那样,它 可以 实际上包括 setuptools
。问题是在 setup_requires
中包含 setuptools
主要用作文档。它声明 setuptools
是构建要求(运行 setup.py 需要),但如果尚未满足,它将无法满足该要求。
但是,setuptools
在 setup_requires
中的存在在技术上是正确的,并且确实起到了声明要求并要求安装工具验证要求实际上已安装的目的(以及其他安装-时间要求)。
然而,它只是一个遗留的工件,并没有提供那么多的价值,而且从问题和答案中可以看出,它确实会导致混淆。推荐的正确方法是使用 PEP 517 和 518 声明和构建器,但生态系统的那部分尚未成熟,因此 setuptools 遗迹将保留。尽量不要让他们打扰你。
importlib_resources
backport for Python < 3.7 of the 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.
Why does setup_requires includes setuptools? This does not seem to make sense
完全没有意义。另一方面,它不会妨碍任何事情,为什么不呢?
不,setuptools
不应包含在 setup_requires
中,根据 PEP 518(粗体强调我的):
Setuptools tried to solve this with a
setup_requires
argument to itssetup()
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
, butsetup.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 thesetup()
function.- This cannot include
setuptools
itself nor can it include a replacement tosetuptools
, which means that projects such asnumpy.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 thesetup.py
but one of the common ways that thesetup.py
is executed is via another tool, such aspip
, who is already managing dependencies. This means that a command likepip install spam
might end up having both pip and setuptools downloading and installing packages and end users needing to configure both tools (and forsetuptools
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.
接受的答案大部分是正确的,但 PEP 518 说的是。
[The
setup_requires
mechanism] cannot includesetuptools
itself...
它在技术上是不正确的,正如 importlib_resources
所证明的那样,它 可以 实际上包括 setuptools
。问题是在 setup_requires
中包含 setuptools
主要用作文档。它声明 setuptools
是构建要求(运行 setup.py 需要),但如果尚未满足,它将无法满足该要求。
但是,setuptools
在 setup_requires
中的存在在技术上是正确的,并且确实起到了声明要求并要求安装工具验证要求实际上已安装的目的(以及其他安装-时间要求)。
然而,它只是一个遗留的工件,并没有提供那么多的价值,而且从问题和答案中可以看出,它确实会导致混淆。推荐的正确方法是使用 PEP 517 和 518 声明和构建器,但生态系统的那部分尚未成熟,因此 setuptools 遗迹将保留。尽量不要让他们打扰你。