为什么在Python打包教程中setup.cfg的package_dir设置多行?

Why is setup.cfg's package_dir setting on multiple lines in Python packaging tutorial?

我正在关注 a tutorial 开发 Python 软件包。在本教程中,他们展示了如何设置基本 setup.cfg 文件,如下所示。

[metadata]
name = example-pkg-YOUR-USERNAME-HERE
version = 0.0.1
author = Example Author
author_email = author@example.com
description = A small example package
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/pypa/sampleproject
project_urls =
    Bug Tracker = https://github.com/pypa/sampleproject/issues
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

[options]
package_dir =
    = src
packages = find:
python_requires = >=3.6

[options.packages.find]
where = src

我的问题与这部分有关。

package_dir =
    = src

我不明白为什么这会延伸到多行。当我用一行替换这两行时 package_dir = src 我在尝试构建时发现以下错误。

distutils.errors.DistutilsOptionError: Unable to parse option value to dict: src

ERROR Backend subproccess exited when trying to invoke get_requires_for_build_sdist

多行或赋值运算符的明显必要性是怎么回事?

您实际上可以在同一页面中找到更多信息

package_dir is a mapping of package names and directories. An empty package name represents the “root package” — the directory in the project that contains all Python source files for the package — so in this case the src directory is designated the root package.

package_dir = 是配置参数

= src 表示包名为空因此

empty package name represents the “root package”

确保 = src 不是未缩进的。它应该总是看起来像:

[options]
package_dir =
    = src

package_dir 将包映射到它们的文件夹,而 = src 被解析为 Python 字典作为 {'': 'src'}。 = src 表示 ./src 包含你的发行版的所有包