This repository has been archived by the owner on Apr 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
generate
executable file
·181 lines (160 loc) · 6.95 KB
/
generate
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
import sys
import os
import inspect
import pkg_resources
import fnmatch
def collect_registered_bears_dirs(entrypoint):
"""
Searches setuptools for the entrypoint and returns the bear
directories given by the module.
:param entrypoint: The entrypoint to find packages with.
:return: List of bear directories.
"""
collected_dirs = []
for ep in pkg_resources.iter_entry_points(entrypoint):
registered_package = None
try:
registered_package = ep.load()
except pkg_resources.DistributionNotFound:
continue
collected_dirs.append(os.path.abspath(
os.path.dirname(registered_package.__file__)))
return collected_dirs
from glob import glob
from collections import OrderedDict
from bear_docs_utils import get_bears
from language_generate import language_generate
def text_wrap(*args, delimiter=' ', end='\n', limit=80):
"""
Breaks it wordwise when going further than ``limit`` chars.
:param args:
The stuff you want to have printed.
:param delimiter:
Will be placed between all the args.
:param limit:
Char limit.
:param end:
An ending, will be put as last character and doesn't count into the
char limit.
:return:
A list of strings, each element to be written on its own line.
"""
output = delimiter.join(args)
lines = output.splitlines(keepends=True)
results = []
for line in lines:
curr_print = line
while len(curr_print.rstrip('\n')) > limit:
splitpos = curr_print[:limit].rfind(' ')
if splitpos < 0:
# Word too long, search for a space left from limit at least
splitpos = curr_print.find(' ')
if splitpos < 0:
break # Break out and add the long thing in the next line
results.append(curr_print[:splitpos])
curr_print = curr_print[splitpos+1:]
results.append(curr_print)
return results
if __name__ == "__main__":
bears = get_bears()
path = collect_registered_bears_dirs("coalabears")[0]
for bear in bears:
meta = bear.get_metadata()
if bear.name == "ClangFunctionDifferenceBear":
continue
matches = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, bear.name + '.py'):
matches.append(os.path.join(root, filename))
rel_path = os.path.relpath(matches[0], path)
url = "https://github.com/coala/coala-bears/tree/master/bears/" + rel_path
output = "`" + bear.name + " <" + url + ">`_\n"
output += "=" * (len(output) - 1) + "\n\n"
output += meta.desc + "\n\n"
sup = "`Supported Languages <../README.rst>`_"
output += sup + "\n"
output += "-" * len(sup) + "\n\n"
output += "\n".join(["* " + x for x in sorted(bear.LANGUAGES)])
output += "\n\n"
par = {}
lmax = -1
rmax = -1
for param in meta.non_optional_params:
if param in meta.deprecated_params:
continue
key = " ``" + param + "`` "
par[key] = text_wrap(meta.non_optional_params[param][0], limit=60)
par[key] = [g.strip() for g in par[key]]
lmax = max(lmax, len(key))
rmax = max(rmax, max(len(g) for g in par[key]))
for param in meta.optional_params:
if param in meta.deprecated_params:
continue
key = " ``" + param + "`` "
description = bear.get_metadata().optional_params[param][0]
if param == 'scalalint_config':
description = ('Path to a custom configuration file. '
'(Optional, defaults to packaged XML file.)')
par[key] = text_wrap(description, limit=60)
par[key] = [g.strip() for g in par[key]]
lmax = max(lmax, len(key))
rmax = max(rmax, max(len(g) for g in par[key]))
if len(par):
lmax = max(lmax, len(" Setting"))
rmax = max(rmax, len("Meaning"))
header = False
for key in sorted(par):
if not header:
output += "Settings\n--------\n\n"
output += "+" + "-" * (lmax) + "-+-" + "-" * (1 + rmax) + "+\n"
output += "| Setting" + " " * (lmax - len(" Setting")) + " | Meaning" + " " * (rmax - len("Meaning")) + "|\n"
output += "+" + "=" * lmax + "=+=" + "=" * (1 + rmax) + "+\n"
header = True
output += "| " + " " * lmax + "| " + " " * (1 + rmax) + "|\n"
output += "|" + key + " " + " " * (lmax - len(key)) + "| " + par[key][0] + " " * (1 + rmax - len(par[key][0]))
if len(par[key]) > 1:
output += "|\n"
else:
output += "+\n"
for text in par[key][1:]:
output += "|" + " " * (lmax + 1) + "| " + text + " " * (1 + rmax - len(text)) + "|\n"
output += "| " + " " * lmax + "| " + " " * (1 + rmax) + "|\n"
output += "+" + "-" * lmax + "-+-" + "-" * (1 + rmax) + "+\n"
if bear.ASCIINEMA_URL:
output += "\n\nDemo\n----\n\n"
output += """|asciicast|
.. |asciicast| image:: {}.png
:target: {}?autoplay=1
:width: 100%""".format(bear.ASCIINEMA_URL, bear.ASCIINEMA_URL)
if bear.REQUIREMENTS:
output += "\n\nDependencies\n------------\n\n"
outs = []
for requirement in bear.REQUIREMENTS:
if hasattr(requirement, 'type'):
outs.append("* ``" + requirement.type + "``"
" - ``" + requirement.package + "``")
else:
outs.append("* System requirement\n")
for system, package in requirement.package.items():
outs[-1] += " - ``" + system + "`` - ``" + package + "``"
output += "\n".join(sorted(outs))
output += "\n"
if len(bear.can_detect):
output += "\n\nCan Detect\n----------\n\n"
output += "\n".join(sorted(["* " + x for x in bear.can_detect]))
if len(bear.CAN_FIX):
output += "\n\nCan Fix\n----------\n\n"
output += "\n".join(sorted(["* " + x for x in bear.CAN_FIX]))
if bear.LICENSE:
output += "\n\nLicense\n-------\n\n"
output += bear.LICENSE
if len(bear.AUTHORS):
output += "\n\nAuthors\n-------\n\n"
for author, author_email in zip(bear.AUTHORS, bear.AUTHORS_EMAILS):
output += "* " + author + " (" + author_email + ")\n"
with open("docs/" + bear.name + ".rst", "w") as bear_file:
bear_file.write(output)
language_generate()
if len(sys.argv) == 1:
os.system("git add -A && git commit -m 'Docs Update' && git push")