forked from scrtlabs/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_conda_packages.py
60 lines (44 loc) · 1.71 KB
/
make_conda_packages.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
import os
import re
import subprocess
def get_immediate_subdirectories(a_dir):
return [name for name in os.listdir(a_dir)
if os.path.isdir(os.path.join(a_dir, name))]
def iter_stdout(cmd):
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
try:
for line in iter(p.stdout.readline, b''):
yield line.decode().rstrip()
finally:
retcode = p.wait()
if retcode:
raise subprocess.CalledProcessError(retcode, cmd[0])
PKG_PATH_PATTERN = re.compile(".* anaconda upload (?P<pkg_path>.+)$")
def main(env, do_upload):
for recipe in get_immediate_subdirectories('conda'):
cmd = ["conda", "build", os.path.join('conda', recipe),
"--python", env['CONDA_PY'],
"--numpy", env['CONDA_NPY'],
"--skip-existing",
"-c", "quantopian/label/ci",
"-c", "quantopian"]
output = None
for line in iter_stdout(cmd):
print(line)
if not output:
match = PKG_PATH_PATTERN.match(line)
if match:
output = match.group('pkg_path')
if output and os.path.exists(output) and do_upload:
cmd = ["anaconda", "-t", env['ANACONDA_TOKEN'],
"upload", output, "-u", "quantopian", "--label", "ci"]
for line in iter_stdout(cmd):
print(line)
if __name__ == '__main__':
env = os.environ.copy()
main(env,
do_upload=((env.get('ANACONDA_TOKEN')
and env.get('APPVEYOR_REPO_BRANCH') == 'master')
and 'APPVEYOR_PULL_REQUEST_NUMBER' not in env))