-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsetuptips.py
80 lines (64 loc) · 2.13 KB
/
setuptips.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
"""
Utils for setup.py
"""
import re
# Utils to format RST
def yield_sphinx_only_markup(lines):
"""
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
:param file_inp: a `filename` or ``sys.stdin``?
:param file_out: a `filename` or ``sys.stdout`?`
References
----------
https://stackoverflow.com/questions/16367770/my-rst-readme-is-not-formatted-on-pypi-python-org
Notes
-----
Check output with::
python setup.py --long-description | rst2html.py > output.html
"""
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"),
## added to make docs Pypi compatible
(
r"\.\. image::(?s).*?\n[\r\n]",
r"",
), # remove paragraphs starting with .. image::
(r">`__", r">`_"),
(r"α", r"\\alpha"),
]
regex_subs = [(re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs]
try:
for (regex, sub) in regex_subs:
lines = regex.sub(sub, lines)
except Exception as ex:
print("ERROR: %s, (line(%s)" % (regex, sub))
raise ex
return lines
# for line in lines:
# yield clean_line(line)