/
create-gh-yaml.py
54 lines (43 loc) · 1.5 KB
/
create-gh-yaml.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
from requests import get
from hashlib import sha256
import yaml
from pathlib import Path
org,repo,name,user = 'cli','cli','gh','jph00'
path = Path(name)
path.mkdir(exist_ok=True)
repo_d = get(f'https://api.github.com/repos/{org}/{repo}').json()
desc,url = repo_d['description'],repo_d['html_url']
rels = get(f'https://api.github.com/repos/{org}/{repo}/releases/latest').json()
ver = rels['tag_name'][1:]
rels_d = dict(linux64 = 'linux_amd64',
linux32 = 'linux_386',
osx = 'macOS_amd64')
def get_source(plat, pre):
download = next(o for o in rels['assets']
if o['name'].endswith(f'{pre}.tar.gz'))['browser_download_url']
h = sha256(get(download).content).hexdigest()
spec = f' # [{plat}]'
return f' url: {download}{spec}\n sha256: {h}{spec}\n'
sources = [get_source(*p) for p in rels_d.items()]
# Work around conda build bug - 'package' and 'source' must be first
d1 = f'''package:
name: {name}
version: {ver}
source:
{"".join(sources)}'''
lic = repo_d['license']
d2 = {
'build': {'number': 0, 'binary_relocation': False,
'script': 'cp -r bin share $PREFIX/'},
'test': {'commands': ['gh --help']},
'about': {
'license': lic['name'],
'license_family': lic['spdx_id'],
'home': url, 'doc_url': url, 'dev_url': url
},
'extra': {'recipe-maintainers': [user]}
}
yaml.SafeDumper.ignore_aliases = lambda *args : True
with (path/'meta.yaml').open('w') as f:
f.write(d1)
yaml.safe_dump(d2, f)