setup.py:'description' 中的换行符

setup.py: linebreak in 'description'

我想在简短描述的单独一行中包含 import 语句。

setup(
    name='my-module',
    packages=find_packages(),
    license='MIT',
    description='A useful module. \nfrom my_module import MyModule',
    long_description=README,
    long_description_content_type='text/markdown',
)

但是,一旦我在我的描述中包含 \n 字符,我在 长描述 中收到以下错误 运行 twine check dist/*:

Checking dist\mymodule-1.0-py3-none-any.whl: FAILED
  `long_description` has syntax errors in markup and would not be rendered on PyPI.
    line 7: Error: Unexpected indentation.
  warning: `long_description_content_type` missing.  defaulting to `text/x-rst`.
Checking dist\mymodule-1.0.tar.gz: FAILED
  `long_description` has syntax errors in markup and would not be rendered on PyPI.
    line 7: Error: Unexpected indentation.
  warning: `long_description_content_type` missing.  defaulting to `text/x-rst`.

显然 setup.py 中的换行符没有被正确解析 - 描述中通常不可能有换行符,还是我必须以不同的方式使用它?

python setuptools docs 指定 description 字段必须是“短字符串”。这可能听起来像通用英语,但具有语义意义,如后所述-

‘short string’

A single line of text, not more than 200 characters.

问题就在这里。该字符串必须是 单行 (无换行符)- 并且最多也必须是 200 个字符。

您的(短)description= 中不能有 newlines/linebreaks。

这令人惊讶,至少检查器的行为是这样,但这是一个已知问题,截至 2020 年 11 月 it's being solved