How to ensure that README.rst is valid?

空扰寡人 提交于 2019-12-17 19:23:52

问题


There are two version of my little tool:

  • https://pypi.python.org/pypi/tbzuploader/2017.11.0
  • https://pypi.python.org/pypi/tbzuploader/2017.12.0 Bug: The pypi page looks ugly.

In the last update a change in README.rst cases a warning:

user@host> rst2html.py README.rst  > /tmp/foo.html
README.rst:18: (WARNING/2) Inline emphasis start-string without end-string.
README.rst:18: (WARNING/2) Inline emphasis start-string without end-string.

Now the pypi page looks ugly :-(

I use this recipe to do CI, bumpversion, upload to pypi: https://github.com/guettli/github-travis-bumpversion-pypi

How could I ensure that no broken README.rst gets released any more? With other words I want to avoid that the pypi page looks ugly.

Dear detail lovers: Please don't look into the current particular error in the README.rst. That's is not the question :-)


回答1:


Update

As of Sep 21, 2018, the Python Packaging Authority recommends an alternative command twine check. To install twine:

pip install twine
twine check dist/*

Note that twine requires readme_renderer. You could still use readme_renderer, and you only need to install twine if you want its other features, which is a good idea anyway if you are releasing to PyPI.


From the official Python packaging docs, Uploading your Project to PyPI:

Tip: The reStructuredText parser used on PyPI is not Sphinx! Furthermore, to ensure safety of all users, certain kinds of URLs and directives are forbidden or stripped out (e.g., the .. raw:: directive). Before trying to upload your distribution, you should check to see if your brief / long descriptions provided in setup.py are valid. You can do this by following the instructions for the pypa/readme_renderer tool.

And from that tool's README.rst:

To check your long description's locally simply install the readme_renderer library using:

$ pip install readme_renderer
$ python setup.py check -r -s



回答2:


You could try if rstcheck catches the type of error in your readme. If it does, run it after pytest in your script section. (and add it in your requirements ofc).




回答3:


Preamble

I had a readme which would not render on PyPi, other than the first element on the page (an image). I ran the file against multiple validators, and tested it against other renders. It worked perfectly fine everywhere else! So, after a long, nasty fight with it, and numerous version bumps so I could test a PyPi revision, I tried reducing the file to a bare minimum, from which I'd build it back up. It turned out that the first line was always processed, and then nothing else was...

Solution

Discovering this clue regarding the first line, I then had an epiphany... All I had to do was change the line endings in the file! I was editing the file in Windows, with Windows line endings being tacked on implicitly. I changed that to Unix style and (poof!) PyPi fully rendered the doc!

Rant...

I've encountered such things in the past, but I took it for granted that PyPi would handle cross platform issues like this. I mean one of the key features of Python is being cross platform! Am I the first person working in Windows to encounter this?! I don't appreciate the hours of time this wasted.



来源:https://stackoverflow.com/questions/46682793/how-to-ensure-that-readme-rst-is-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!