PyPi描述降价不起作用

Mar*_*oun 55 python restructuredtext pypi

我使用以下方法将包上传到PyPi:

python setup.py register -r pypi
python setup.py sdist upload -r pypi
Run Code Online (Sandbox Code Playgroud)

我正在尝试修改decsription,我写道(请不要编辑以下代码片段的格式,我是为了演示我的问题而制作的):

**my plugin**

This plugin enables you to ... For example:
```python
@attr(section='MySection', id=1)
def test_function(self):
    """
    Bla bla bla
    """
    pass
```
Run Code Online (Sandbox Code Playgroud)

但是,文本显示为原样,没有降价格式.我究竟做错了什么?

Mar*_*ers 97

截至2018年3月16日,PyPI.org aka Warehouse(最后)在长描述中支持Markdown.Warehouse于2018年4月取代了旧的传统PyPI实施.

你需要:

旧的传统PyPI基础架构不会呈现Markdown,只有新的Warehouse基础架构才能实现.遗留基础设施现已消失(截至2018-04-30).

目前,PyPI cmarkgfm通过readme_renderer(readme_renderer.markdown.render(long_description)用于生成HTML输出)用作降价渲染器.这意味着您的降价文档将呈现 GitHub 完全相同的内容 ; 它基本上是相同的渲染器.

您可以long_description使用twine check命令(twine1.12.0或更高版本)验证您的包.

旧的<2018-03-16答案如下.


注意:这是旧的,现在过时的答案,截至2018-03-16支持Markdown,前提是您使用正确的工具,见上文.

PyPI将它支持降价,所以你的自述不会被渲染成HTML.

如果你想要一个渲染的自述文件,请坚持使用reStructuredText; 在狮身人面像的介绍新结构化是一个很好的起点.

您可能希望安装该docutils软件包,以便在本地测试您的文档; 您希望rst2html.py在README上运行包含的脚本,以查看生成的错误(如果有).您的特定样本有太多错误:

$ 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.
Run Code Online (Sandbox Code Playgroud)

您的代码块使用的是Github的Markdown扩展,这对于reStructuredText完全错误.您可以使用reST代码块(可能,如果Docutil的PyPI版本足够新):

.. code-block:: python

    @attr(section='MySection', type='functional+', module='MyModule', id=1)
    def test_function(self):
        """
        This is the original docstring
        """
        pass
Run Code Online (Sandbox Code Playgroud)

要在本地测试,您还需要安装Pygments.

有一个上拉的请求功能要求添加支持降价,如果你有兴趣.


Mat*_*kin 56

如上所述@Martijn Pieters,PyPi不支持Markdown.我不确定在哪里学到了以下技巧,但是你可以使用PandocPyPandoc将你的Markdown文件转换成RestructuredText,然后再上传到PyPi.要完成此操作,请将以下内容添加到您的setup.py文件中:

try:
    import pypandoc
    long_description = pypandoc.convert('README.md', 'rst')
except(IOError, ImportError):
    long_description = open('README.md').read()

setup(
    name='blah',
    version=find_version('blah.py'),
    description='Short description',
    long_description=long_description,
)
Run Code Online (Sandbox Code Playgroud)

要在OS X上安装Pandoc,我使用了Homebrew:

brew install pandoc
Run Code Online (Sandbox Code Playgroud)

要安装PyPandoc,我使用了pip:

pip install pypandoc
Run Code Online (Sandbox Code Playgroud)

  • 旁边的问题:为什么还要抓住`IOError`?在这种情况下,`ImportError`不是唯一的预期异常吗? (2认同)

Chi*_*nke 14

PyPI支持rst,而不是其他答案中提到的降价.但你不需要pypandoc坚持,只是pandoc没事.您可以先在本地生成第一个文件,然后运行setup.py来上传包.

upload.sh:

#!/bin/bash
pandoc --from=markdown --to=rst --output=README README.md
python setup.py sdist upload
Run Code Online (Sandbox Code Playgroud)

生成的文件README将被自动识别.一定要把它添加到你的.gitignore!在setup.py没有做任何特殊.

setup.py:

from distutils.core import setup

setup(
    name='mypackage',
    packages=['mypackage'],  # this must be the same as the name above
    version='0.2.8',
    description='short',
    author='Chiel ten Brinke',
    author_email='<email>',
    url='<github url>',  # use the URL to the github repo
    keywords=[],  # arbitrary keywords
    classifiers=[],
)
Run Code Online (Sandbox Code Playgroud)

然后运行bash upload.sh将内容上传到PyPI.

  • 在我的情况下,README文件不会自动识别为long_description.必须将long_description字段添加到setup.py.否则,README文件将不会在pypi上呈现. (3认同)

bet*_*pfa 12

setup.cfg您也可以在文件中设置 markdown :

[metadata]
...
long_description = file: README.md
long_description_content_type = text/markdown
Run Code Online (Sandbox Code Playgroud)

以我的项目为例:在githubpypi上。

  • **注意:**此答案之前将特定于 [pbr (Python Build Reasonableness)](https://docs.openstack.org/pbr/latest/user/features.html) 的非标准“描述文件”密钥与标准“长描述内容类型”键*不*特定于 pbr。此后,我通过更喜欢标准的“long_description”和“long_description_content_type”键来编辑了该错误的差异。现在,无论您是否使用 pbr,这个答案都符合每个人的预期。包装世界现在一切顺利。 (2认同)