当我将我的包提交到Python包索引(https://pypi.python.org/pypi)时,我的README文件(使用有效的reStructuredText编写并保存为README.rst)显示为纯文本而没有任何格式.
我通过验证器(rstctl和collective.checkdocs)运行它,并且不返回任何错误.
我的软件包位于:https: //pypi.python.org/pypi/lcinvestor
它位于github:https: //github.com/jgillick/LendingClubAutoInvestor
Jer*_*ick 26
事实证明@sigmavirus关于链接的答案很接近.我开始讨论 distutils邮件列表,发现pypi reStructuredText解析器不允许使用页内链接(即#minimum-cash),并使整个文档无效.
似乎pypi使用白名单来过滤链接协议(http vs ftp vs gopher),并将'#'视为无效协议.看起来这很容易修复到他们的结尾,但在那之前,我将删除我的页内锚链接.
ank*_*tis 22
您可以使用collective.checkdocs
包来检测无效的结构:
pip install collective.checkdocs
python setup.py checkdocs
然后,您可以使用以下python函数过滤掉仅限sphinx的构造(可能需要添加更多正则表达式以匹配您的内容):
#!/usr/bin/python3
"""
Cleans-up Sphinx-only constructs (ie from README.rst),
so that *PyPi* can format it properly.
To check for remaining errors, install ``sphinx`` and run::
python setup.py --long-description | sed -file 'this_file.sed' | rst2html.py --halt=warning
"""
import re
import sys, io
def yield_sphinx_only_markup(lines):
"""
:param file_inp: a `filename` or ``sys.stdin``?
:param file_out: a `filename` or ``sys.stdout`?`
"""
substs = [
## Selected Sphinx-only Roles.
#
(r':abbr:`([^`]+)`', r'\1'),
(r':ref:`([^`]+)`', r'`\1`_'),
(r':term:`([^`]+)`', r'**\1**'),
(r':dfn:`([^`]+)`', r'**\1**'),
(r':(samp|guilabel|menuselection):`([^`]+)`', r'``\2``'),
## Sphinx-only roles:
# :foo:`bar` --> foo(``bar``)
# :a:foo:`bar` XXX afoo(``bar``)
#
#(r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'),
(r':(\w+):`([^`]*)`', r'\1(``\2``)'),
## Sphinx-only Directives.
#
(r'\.\. doctest', r'code-block'),
(r'\.\. plot::', r'.. '),
(r'\.\. seealso', r'info'),
(r'\.\. glossary', r'rubric'),
(r'\.\. figure::', r'.. '),
## Other
#
(r'\|version\|', r'x.x.x'),
]
regex_subs = [ (re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs ]
def clean_line(line):
try:
for (regex, sub) in regex_subs:
line = regex.sub(sub, line)
except Exception as ex:
print("ERROR: %s, (line(%s)"%(regex, sub))
raise ex
return line
for line in lines:
yield clean_line(line)
Run Code Online (Sandbox Code Playgroud)
和/或在你的setup.py
文件中,使用类似这样的东西::
def read_text_lines(fname):
with io.open(os.path.join(mydir, fname)) as fd:
return fd.readlines()
readme_lines = read_text_lines('README.rst')
long_desc = ''.join(yield_sphinx_only_markup(readme_lines)),
Run Code Online (Sandbox Code Playgroud)
或者,您可以将sed
unix-utility与此文件一起使用:
## Sed-file to clean-up README.rst from Sphinx-only constructs,
## so that *PyPi* can format it properly.
## To check for remaining errors, install ``sphinx`` and run:
##
## sed -f "this_file.txt" README.rst | rst2html.py --halt=warning
##
## Selected Sphinx-only Roles.
#
s/:abbr:`\([^`]*\)`/\1/gi
s/:ref:`\([^`]*\)`/`\1`_/gi
s/:term:`\([^`]*\)`/**\1**/gi
s/:dfn:`\([^`]*\)`/**\1**/gi
s/:\(samp\|guilabel\|menuselection\):`\([^`]*\)`/``\1``/gi
## Sphinx-only roles:
# :foo:`bar` --> foo(``bar``)
#
s/:\([a-z]*\):`\([^`]*\)`/\1(``\2``)/gi
## Sphinx-only Directives.
#
s/\.\. +doctest/code-block/i
s/\.\. +plot/raw/i
s/\.\. +seealso/info/i
s/\.\. +glossary/rubric/i
s/\.\. +figure::/../i
## Other
#
s/|version|/x.x.x/gi
Run Code Online (Sandbox Code Playgroud)
Ser*_*gar 13
您可以使用以下命令查找将在PyPI上显示的RST中的错误:
python setup.py check --restructuredtext
Run Code Online (Sandbox Code Playgroud)
突然出现的第一件事(在快速扫描之后)是在高级过滤器部分中,您在链接后使用两个下划线,例如,
`Link text <http://example.com>`__
Run Code Online (Sandbox Code Playgroud)
它应该在哪里
`Link text <http://example.com>`_
Run Code Online (Sandbox Code Playgroud)
令人奇怪的是,reStructuredText检查器没有抓住它.如果你也安装了docutils,你可以运行rst2html.py README.rst
它,它应该打印出HTML.如果有错误,它将失败并告诉您错误的位置.
另外,公平警告,列表应该没有前导空格,即你有
- foo
- bar
Run Code Online (Sandbox Code Playgroud)
代替
- foo
- bar
Run Code Online (Sandbox Code Playgroud)
(使其更清晰)
- foo # correct
- one too many for a regular list, it will show up as a quoted list
Run Code Online (Sandbox Code Playgroud)
此外,相对链接不起作用Text to link <#link>_
.如果要链接到单独的部分,则必须执行以下操作:
Here's my `link <section_name>`_ to the other section.
.. Other stuff here ...
.. _section_name:
Min/Max Investment Opportunities and Other Foo Biz Baz
------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
将我的 python 模块上传到 pypi 时我遇到了同样的问题。
后来我检查了README.rst是否存在错误,rst-lint
这表明我的自述文件是正确的。
我发现问题不在 README 文件中,而是在setup.py本身。
归档时间: |
|
查看次数: |
6361 次 |
最近记录: |