截至 2018 年 3 月 16 日,PyPI.org aka Warehouse(终于)支持长描述的 Markdown。 Warehouse 在 2018 年 4 月替换了旧的旧 PyPI 实施。
你需要:
确保 setuptools 升级到 38.6.0 或更高版本
确保 twine 升级到 1.11.0 或更高版本
确保 wheel 升级到 0.31.0 或更高版本
-
在您的setup() 调用中添加一个名为long_description_content_type 的新字段,并将其设置为'text/markdown':
setup(
long_description="""# Markdown supported!\n\n* Cheer\n* Celebrate\n""",
long_description_content_type='text/markdown',
# ....
)
见PEP 566 - Metadata for Python Software Packages 2.1。
-
使用twine 将您的分配上传到 PyPI:
$ python setup.py sdist bdist_wheel # adjust as needed
$ twine upload dist/*
旧的旧 PyPI 基础架构不会渲染 Markdown,只有新的 Warehouse 基础架构可以。旧版基础架构现已不复存在(截至 2018 年 4 月 30 日)。
目前,PyPI 通过readme_renderer library 使用cmarkgfm 作为降价渲染器(使用readme_renderer.markdown.render(long_description) 生成HTML 输出)。这意味着您的降价文档将呈现与 GitHub 上的完全相同;它本质上是相同的渲染器。
您可以使用twine check command(twine 1.12.0 或更高版本)验证您的包long_description。
下面是
注意:这是旧的,现在已经过时的答案,从 2018 年 3 月 16 日起,只要您使用正确的工具,就支持 Markdown,见上文。
PyPI 不支持 Markdown,所以你的 README 不会被渲染成 HTML。
如果你想要一个渲染的 README,坚持使用 reStructuredText; Sphinx introduction to reStructuredText 是一个很好的起点。
您可能想要安装docutils package,以便在本地测试您的文档;您想在 README 中运行包含的 rst2html.py 脚本,以查看产生了哪些错误(如果有)。您的具体示例有太多错误:
$ bin/rst2html.py test.rst > /tmp/test.html
test.rst:7: (ERROR/3) Unexpected indentation.
test.rst:3: (WARNING/2) Inline literal start-string without end-string.
test.rst:3: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
test.rst:11: (WARNING/2) Block quote ends without a blank line; unexpected unindent.
test.rst:11: (WARNING/2) Inline literal start-string without end-string.
test.rst:11: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
您的代码块正在使用 Github 的 Markdown 扩展,这对于 reStructuredText 是完全错误的。您可以使用 reST 代码块(可能,如果 docutils 的 PyPI 版本足够新):
.. code-block:: python
@attr(section='MySection', type='functional+', module='MyModule', id=1)
def test_function(self):
"""
This is the original docstring
"""
pass
要在本地进行测试,您还需要安装 Pygments。
如果你有兴趣,有一个feature request with pull request 可以添加对 Markdown 的支持。