forked from datalad/datalad-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·218 lines (171 loc) · 8.23 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python3
import os
import os.path as op
import glob
import sys
import yaml
import jinja2
top_path = op.dirname(op.dirname(__file__))
# TODO: proper logigng etc
def log(msg, *args):
print(msg % args)
class ExtensionSpec(dict):
@property
def name(self):
return self["name"]
# Some properties which might tune the value
@property
def github(self):
from_spec = self.get("github", self.name.replace("_", "-"))
gh_url = "datalad/{}".format(from_spec) \
if '/' not in from_spec else from_spec
return gh_url
@property
def githubdash(self):
return self.github.replace("_", "-")
@property
def githubname(self):
return self.github.split('/')[1]
@property
def pypi(self):
return self.get("pypi", self.name)
@property
def package(self):
return self.get("package", self.name)
@property
def conda(self):
return self.get('conda', self.package.replace('_', '-'))
@property
def apt_depends(self):
return self.get("apt_depends", [])
@property
def tester(self):
return self.get('tester', 'nose')
#def __getattribute__(self, item):
# return self[item]
def jinja_render(tmpl, **kwargs):
"""Custom renderer, so we first replace github actions ${{ with a
custom placeholder to avoid jinja tying to handle it
"""
PLACEHOLDER = "[[["
if PLACEHOLDER in tmpl:
raise RuntimeError(
"Detected placeholder %r already being present in the text"
% PLACEHOLDER
)
tmpl_ = tmpl.replace("${{", PLACEHOLDER)
out_ = jinja2.Template(tmpl_).render(**kwargs)
return out_.replace(PLACEHOLDER, "${{")
def process_extension(ext_spec):
render_kwargs = {
"extension": ext_spec,
}
# TODO: proper recursive
templates_dir = op.join(top_path, 'templates')
for tmpl_p in glob.glob(op.join(templates_dir, '.github/*/*')):
p = jinja_render(tmpl_p, **render_kwargs)
if p == tmpl_p:
log("Skipping %s since seems to be not extension specific", tmpl_p)
continue
with open(tmpl_p) as f:
tmpl = f.read()
rendered = jinja_render(tmpl, **render_kwargs)
if rendered == tmpl:
raise RuntimeError(
f"Rendered version of {tmpl_p} content is the same as template. "
"At the moment it is not expected"
)
prel_target = op.relpath(p, templates_dir)
p_target = op.join(top_path, prel_target)
if not op.exists(op.dirname(p_target)):
os.makedirs(op.dirname(p_target))
with open(p_target, "w") as f:
f.write(rendered)
log("Rendered %s", prel_target)
def generate_README(ext_specs):
with open(op.join(top_path, "README.md"), "w") as f:
f.write("""\
# DataLad healthchecks
This is a "dashboard" of various CIs of DataLad, its extensions, and underlying
3-rd party projects like git-annex.
**This README.md is autogenerated - do not edit.
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.**
## Git-annex Status
- Conda: 


- Current snapshot build/tests + DataLad tests:
[](https://github.com/datalad/datalad-extensions/actions?query=workflow%3A%22Build+git-annex+snapshot%22)
## DataLad Status
[](https://GitHub.com/datalad/datalad/releases/)
[](https://pypi.python.org/pypi/datalad/)

- CI:
[](https://travis-ci.org/datalad/datalad)
[](https://ci.appveyor.com/project/mih/datalad/branch/master)
[](http://datalad.rtfd.org)
- Misc:
[](https://codecov.io/github/datalad/datalad?branch=master)
## DataLad Extensions Status
""")
columns = {
'Name': 'ref',
'Release': 'release_github',
'PyPI Release': 'release_pypi',
'Conda Release': 'release_conda',
'CI: Released + DL master': 'ci_rel+dlmaster',
'CI: master + DL Release': 'ci_master+dlrelease',
'Codecov': 'codecov',
'Issue Resolution': 'issues_restime',
'Open Issues': 'issues_open'
}
def write_row(entries):
f.write(' | '.join([''] + entries + ['']) + '\n')
# Header
write_row(list(columns))
write_row(['---']*len(columns))
# TODO: link to per-extension cron-github-CI results
https_extension = "https://github.com/datalad/datalad-extensions"
for ext, e in ext_specs.items():
entry = {
'ref': f"[{ext}](https://github.com/{e.github})",
'release_github': f'[](https://GitHub.com/{e.githubdash}/releases/)',
'release_pypi': f'[](https://pypi.python.org/pypi/{e.pypi}/)',
'release_conda': f'',
'ci_rel+dlmaster': f'[]({https_extension}/actions?query=workflow%3Atest-{ext})',
'ci_master+dlrelease': f'[](https://travis-ci.org/{e.githubdash})',
'codecov': f'[](https://codecov.io/github/{e.githubdash}?branch=master)',
'issues_restime': f'[](http://isitmaintained.com/project/{e.githubdash} "Average time to resolve an issue")',
'issues_open': f'[](http://isitmaintained.com/project/{e.githubdash} "Percentage of issues still open")',
}
write_row([entry[k] for k in columns.values()])
# [](https://doi.org/10.5281/zenodo.3368666)
# f"[](http://{e.githubname}.rtfd.org)"
# f"[](
# https://opensource.org/licenses/MIT)
def main(extensions):
ext_specs = load_ext_specs()
for ext in extensions or list(ext_specs):
process_extension(ext_specs[ext])
# We generate/update README.md for all extensions for now
generate_README(ext_specs)
def load_ext_specs():
with open(op.join(top_path, "extensions.yaml")) as f:
spec = yaml.load(f.read(), Loader=yaml.BaseLoader)
# ATM expecting only a single structure
assert list(spec.keys()) == ['extensions']
ext_specs = spec["extensions"]
for ext in list(ext_specs):
if not ext_specs[ext]: # Was None
# If it had nothing -- prepare it to be a dict
ext_specs[ext] = {}
ext_spec = ext_specs[ext] \
= ExtensionSpec(**ext_specs[ext])
ext_spec["name"] = ext
return ext_specs
if __name__ == "__main__":
main(sys.argv[1:])