Skip to main content
 首页 » 编程设计

python之long_description 只包含 README.rst 的第一行

2024年10月24日18zfyouxi

我在使用 README.rst 文件打包此模块时遇到问题。我从 SO 查找了很多帖子,但没有找到任何帮助。

目前,我正在使用一个非常简单的自述文件进行测试

pytelemetry 
=========== 
 
pytelemetry enables remote monitoring and control of embedded 
devices. Specifically, pytelemetry implements a custom communication 
protocol, based on the PubSub messaging pattern. 

这里是 setup.py 文件的概述

here = path.abspath(path.dirname(__file__)) 
# Get the long description from the README file 
with open(path.join(here, 'README0.rst'), encoding='utf-8') as f: 
    long_description = f.read() 
    print(long_description) # Prints the correct readme 
 
setup( 
    name='pytelemetry', 
 
    version='1.1.0', 
 
    description='Lightweight remote monitoring and control of embedded devices', 
    long_description=long_description, # Not working ! 

我使用 python setup.py bdist_wheel 构建包。使用 python 3.5.1,轮子 0.24.0 和 0.29.0。 print(long_description) 工作得很好,但是当我解压缩生成的轮子时,DESCRIPTION.rst 文件(我认为应该包含长描述)只包含:

pytelemetry 

这对应于我的 README.rst 的第一行。在 pypi 上,我得到相同的输出。为什么最后我的自述文件只有第一行?

  • 我认为 DESCRIPTION.rst 包含 long_description 中提供给 setup.py 的任何内容是否正确?
  • 我该如何解决这个问题?
  • 以后如何调试此类问题?

请您参考如下方法:

哇,这是个愚蠢的问题。

失败的脚本是

try: 
    long_description = pypandoc.convert('README.md', 'rst') 
except OSError: 
    print("Pandoc not found. Long_description conversion failure.") 
    import io 
    # pandoc is not installed, fallback to using raw contents 
    with io.open('README.md', encoding="utf-8") as f: 
        long_description = f.read() 

我添加了这一行:

try: 
    long_description = pypandoc.convert('README.md', 'rst') 
    long_description = long_description.replace("\r","") # THAT $%^$*($ ONE 
except OSError: 
    print("Pandoc not found. Long_description conversion failure.") 
    import io 
    # pandoc is not installed, fallback to using raw contents 
    with io.open('README.md', encoding="utf-8") as f: 
        long_description = f.read() 

现在,如果我解压缩生成的轮子,我可以在 DESCRIPTION.rst 中看到我的完整自述文件!耶。 我不确定是什么导致了这个问题,或者是 pypandoc 还是设置函数有问题。

为了找到这个解决方案,我简单地访问了 pypandoc 存储库和 had a look at their setup.py file ,正是这样做的。