forked from twisted/treq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tox2travis.py
executable file
·112 lines (87 loc) · 2.54 KB
/
tox2travis.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
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
#!/usr/bin/env python
"""
Generate a Travis CI configuration based on Tox's configured environments.
Usage:
tox -l | ./tox2travis.py > .travis.yml
"""
from __future__ import absolute_import, print_function
import re
import sys
travis_template = """\
# AUTO-GENERATED BY tox2travis.py -- DO NOT EDIT THIS FILE BY HAND!
sudo: false
language: python
cache: pip
matrix:
include:
{includes}
# Don't fail on trunk versions.
allow_failures:
{allow_failures}
before_install:
- |
if [[ "${{TOXENV::5}}" == "pypy-" ]]; then
PYENV_ROOT="$HOME/.pyenv"
git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install pypy-5.4.1
pyenv global pypy-5.4.1
fi
- pip install --upgrade pip
- pip install --upgrade setuptools
install:
- pip install tox codecov
script:
- tox
after_success:
- codecov
after_failure:
- |
if [[ -f "_trial_temp/httpbin-server-error.log" ]]
then
echo "httpbin-server-error.log:"
cat "_trial_temp/httpbin-server-error.log"
fi
notifications:
email: false
branches:
only:
- master
# AUTO-GENERATED BY tox2travis.py -- DO NOT EDIT THIS FILE BY HAND!"""
if __name__ == "__main__":
line = sys.stdin.readline()
tox_envs = []
while line:
tox_envs.append(line.strip())
line = sys.stdin.readline()
includes = []
allow_failures = []
for tox_env in tox_envs:
# Parse the Python version from the tox environment name
python_match = re.match(r'^py(?:(\d{2})|py)-', tox_env)
if python_match is not None:
version = python_match.group(1)
if version is not None:
python = "'{0}.{1}'".format(version[0], version[1])
else:
python = 'pypy'
else:
python = "'2.7'" # Default to Python 2.7 if a version isn't found
includes.extend([
'- python: {0}'.format(python),
' env: TOXENV={0}'.format(tox_env)
])
# Python 3.7 is available on sudo-enabled Xenial VMs only
# See https://github.com/travis-ci/travis-ci/issues/9815
if python == "'3.7'":
includes.extend([
' dist: xenial',
' sudo: true',
])
if 'trunk' in tox_env:
allow_failures.append('- env: TOXENV={0}'.format(tox_env))
print(travis_template.format(
allow_failures='\n '.join(allow_failures),
includes='\n '.join(includes),
))