-
Notifications
You must be signed in to change notification settings - Fork 1
/
recipe_templater.py
68 lines (60 loc) · 1.45 KB
/
recipe_templater.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
import os
import hashlib
from urllib.request import urlopen
from string import Template
from dependency_lookup import get_dependency_string
template_string = """package:
name: $full_name
version: "$version"
source:
url: $url
md5: $md5
build:
script: R CMD INSTALL --build .
number: 0
rpaths:
- lib/R/lib
- lib/
requirements:
build:${dependencies}
run:${dependencies}
test:
commands:
- '$$R -e "library(''${name}'')"'
about:
home: ${home}
license: $license_type
summary: $summary
"""
def generate_meta_yaml(
name,
version,
base_url,
home,
license_type,
summary,
dependencies=[],
prefix="bioconductor-"
):
full_file = name + "_" + version + ".tar.gz"
full_package_name = prefix + name.lower()
url = os.path.join(base_url, full_file)
md5 = hashlib.md5(urlopen(url).read()).hexdigest()
dep_text = ""
for dep in dependencies:
dep_string = get_dependency_string(dep)
dep_text += "\n - {}".format(dep_string)
template = Template(template_string)
text = template.substitute(
name=name,
full_name=full_package_name,
version=version.replace("-", "."),
url=url,
md5=md5,
home=home,
license_type=license_type,
dependencies=dep_text,
summary=summary
)
with open("recipes/{}/meta.yaml".format(full_package_name), "w") as yml_file:
yml_file.write(text)