【发布时间】:2018-05-03 21:16:53
【问题描述】:
我最近在我的.egg-info/PKG-INFO 中发现了一个新的元数据:Description-Content-Type。
当我跑步时:
python setup.py egg_info
我明白了:
Description-Content-Type: UNKNOWN
例如,我如何判断我使用的是 Markdown (text/markdown)?
【问题讨论】:
我最近在我的.egg-info/PKG-INFO 中发现了一个新的元数据:Description-Content-Type。
当我跑步时:
python setup.py egg_info
我明白了:
Description-Content-Type: UNKNOWN
例如,我如何判断我使用的是 Markdown (text/markdown)?
【问题讨论】:
元数据字段Description-Content-Type 是在setuptools v36.4 中引入的(2017 年 9 月)。它在Core Metadata v2.1 中可用。
您可以在setup.py 中使用此元数据来指定您的包Description 的内容类型。
经典用法是用项目的 README 文件填充long_description。
然后,您可以使用long_description_content_type 参数来设置内容类型。
项目的详细描述显示在PyPi(Python 包索引)中。 您可以阅读 PyPA 文章:“Including your README in your package’s metadata”。
这是一个例子:
import io
from setuptools import setup
def read(filename):
with io.open(filename, mode="r", encoding='utf-8') as fd:
return fd.read()
setup(
name="YourProject",
version='1.2.3',
description="One line description of your project",
long_description=read("README.rst"),
long_description_content_type='text/x-rst',
...
)
您可以选择其中一种内容类型:
"text/plain":对于简单的文本(例如:“README”或“README.txt”),"text/x-rst":对于 reStructuredText(例如:“README.rst”),或"text/markdown":用于 Markdown(例如:“README.md”)。注意:最近才支持 Markdown(您需要 setuptools >= 38.6)。
此外,您可以使用twine 来检查您的包的详细描述(一旦构建了可分发包)。例如:
twine check dist/*
【讨论】: