-
Notifications
You must be signed in to change notification settings - Fork 14
/
travis2sh
executable file
·66 lines (58 loc) · 2.29 KB
/
travis2sh
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
#!/usr/bin/env python
""" Process .travis.yml and make sh file for testing
"""
from __future__ import print_function
import sys
from os.path import dirname, splitext
import warnings
import argparse # Python 2.6, really?
# pip install pyyaml
import yaml
sys.path.append(dirname(__file__))
from travisparse import get_envs, TravisError, get_yaml_entry
def main():
parser = argparse.ArgumentParser(
description='Extract sh script from .travis.yml file')
parser.add_argument('in_yml', default='.travis.yml', nargs='?',
help = 'input travis YAML file '
'(default is ".travis.yml")')
parser.add_argument('--no-py-env', action='store_true',
help = 'omit Python virtualenv building'
' and substitute env vars that usually result')
parser.add_argument('--out-sh',
help = 'output sh file name '
'(default is input name with .sh extension) '
'("-" means stdout)')
parser.add_argument('-L', '--local', action='store_true',
help = 'shortcut for "--no-py-env --out-sh -"')
args = parser.parse_args()
if args.local:
args.out_sh = '-'
args.no_py_env = True
with open(args.in_yml, 'rt') as fobj:
travis_dict = yaml.load(fobj)
out_sh = (splitext(args.in_yml)[0] + '.sh' if args.out_sh is None
else args.out_sh)
parts = ['# vars']
try:
parts.append(get_envs(travis_dict).strip())
except TravisError:
warnings.warn('Could not get travis vars from file')
parts += ['# install'] + get_yaml_entry(travis_dict, 'install')
parts += ['# test'] + get_yaml_entry(travis_dict, 'script')
if args.no_py_env:
parts = [part for part in parts
if not part.startswith('get_python_environment')]
parts = ['# Variables usually set by `get_python_environment`',
'export PIP_CMD=pip',
'export PYTHON_EXE=python',
'export VIRTUALENV_CMD=virtualenv'] + parts
content = '\n'.join(parts)
if out_sh == '-':
print(content)
return
with open(out_sh, 'wt') as fobj:
fobj.write(content)
print('Written ' + out_sh)
if __name__ == '__main__':
main()