Skip to content

Commit 104d691

Browse files
committed
wi0
1 parent 2de671b commit 104d691

File tree

5 files changed

+137
-42
lines changed

5 files changed

+137
-42
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ matrix:
3232
dist: xenial
3333
install:
3434
- pip install tox
35-
script: tox -e linters
35+
script: nox -s linters
3636

3737
- python: "3.8"
3838
dist: xenial
@@ -54,14 +54,14 @@ services:
5454
- postgresql
5555

5656
install:
57-
- pip install tox
57+
- bash scripts/travis-install-nox.sh
5858
- pip install codecov
5959
- make install-zeus-cli
6060
- bash scripts/download-relay.sh
6161

6262
script:
6363
- coverage erase
64-
- ./scripts/runtox.sh '' --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
64+
- nox -s travis_test -- --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
6565
- coverage combine .coverage*
6666
- coverage xml -i
6767
- codecov --file coverage.xml

noxfile.py

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import braceexpand
55
import itertools
66

7+
from tox.config import _split_factor_expr
8+
79
MAX_JOBS = 50
810

9-
def expand_factors(value):
11+
def expand_envlist(value):
1012
for line in value.splitlines():
1113
line = line.strip()
1214

@@ -18,65 +20,117 @@ def expand_factors(value):
1820

1921

2022
def find_dependencies(deps, env):
21-
parts = env.split("-")
22-
23-
for combo in itertools.product((True, False), repeat=len(parts)):
24-
key = "-".join(parts[i] for i, include in enumerate(combo) if include)
25-
26-
if key in deps:
27-
yield deps[key]
23+
env_factors = set(env.split("-"))
24+
for (matcher, dependency) in deps.items():
25+
for (included, excluded) in _split_factor_expr(matcher):
26+
if included <= env_factors and not env_factors & excluded:
27+
yield dependency
2828

2929
def parse_tox():
3030
config = configparser.ConfigParser()
3131
config.read("tox.ini")
3232

3333
dependencies = {}
3434

35-
for declaration in expand_factors(config['testenv']['deps']):
36-
if declaration.startswith("-r "):
35+
for line in config['testenv']['deps'].splitlines():
36+
line = line.strip()
37+
if not line or line.startswith(("-r", "#")):
3738
continue
3839

39-
env_matcher, dependency = declaration.split(":", 1)
40+
env_matcher, dependency = line.split(":", 1)
4041
dependencies[env_matcher.strip()] = dependency
4142

42-
jobs = {}
43+
batch_jobs = {}
44+
single_jobs = []
4345

44-
for env in expand_factors(config['tox']['envlist']):
46+
for env in expand_envlist(config['tox']['envlist']):
4547
python_version, integration, framework_version, *_ = (
4648
list(env.split("-")) + [None, None]
4749
)
4850

49-
python_version_jobs = jobs.setdefault(python_version, [])
50-
for job in python_version_jobs:
51-
if job.setdefault(integration, framework_version) == framework_version:
52-
break
51+
python_version_jobs = batch_jobs.setdefault(python_version, [])
52+
53+
if integration is None:
54+
python_version_jobs.append({})
5355
else:
54-
python_version_jobs.append({integration: framework_version})
56+
for job in python_version_jobs:
57+
if job and job.setdefault(integration, framework_version) == framework_version:
58+
break
59+
else:
60+
python_version_jobs.append({integration: framework_version})
61+
62+
single_jobs.append((python_version, integration, framework_version))
5563

56-
return dependencies, jobs
64+
return dependencies, batch_jobs, single_jobs
5765

5866

59-
def generate_sessions(_locals):
60-
dependencies, jobs = parse_tox()
67+
def _format_job_name(python_version, integration, framework_version):
68+
if integration is not None:
69+
return f"{python_version}-{integration}-{framework_version}"
70+
else:
71+
return f"{python_version}"
72+
73+
74+
def generate_test_sessions():
75+
dependencies, batch_jobs, single_jobs = parse_tox()
76+
77+
def add_nox_job(job_name, integrations, python_version, deps):
78+
job_name = job_name.replace(".", "").replace("-", "_")
79+
80+
def func(session):
81+
session.install("-e", ".")
82+
session.install("-r", "test-requirements.txt", *deps)
83+
session.env['COVERAGE_FILE'] = f'.coverage-{job_name}'
84+
session.run(
85+
"pytest",
86+
*[f"tests/integrations/{integration}" for integration in integrations],
87+
*session.posargs
88+
)
6189

62-
for python_version, batches in jobs.items():
90+
assert python_version.startswith("py")
91+
nox_python_version = "pypy" if python_version == "pypy" else python_version[2:]
92+
93+
globals()[job_name] = nox.session(
94+
func=func, reuse_venv=True, python=nox_python_version, name=job_name
95+
)
96+
97+
for (python_version, integration, framework_version) in single_jobs:
98+
job_name = _format_job_name(python_version,integration,framework_version)
99+
deps = list(find_dependencies(dependencies, job_name))
100+
101+
add_nox_job(f"test-{job_name}", [integration], python_version, deps)
102+
103+
for python_version, batches in batch_jobs.items():
63104
for batch_name, integrations in enumerate(batches):
64-
job_name = f"{python_version}-{batch_name}"
105+
job_name = f"batchtest-{python_version}-{batch_name}"
65106
deps = []
66-
for integration, version in integrations.items():
107+
for integration, framework_version in integrations.items():
67108
deps.extend(find_dependencies(
68-
dependencies, f"{python_version}-{integration}-{version}"
109+
dependencies,
110+
_format_job_name(python_version, integration, framework_version)
69111
))
70112

71-
def func(session, deps=deps):
72-
session.install("-r", "test-requirements.txt", *deps)
113+
add_nox_job(job_name, integrations, python_version, deps)
73114

74-
assert python_version.startswith("py")
75-
nox_python_version = "pypy" if python_version == "pypy" else python_version[2:]
76115

77-
_locals[job_name] = nox.session(
78-
func=func, reuse_venv=True, python=nox_python_version, name=job_name
79-
)
116+
@nox.session(python="3.8")
117+
def linters(session):
118+
session.install("-r", "linter-requirements.txt")
119+
120+
session.run(*"flake8 tests examples sentry_sdk".split())
121+
session.run(*"black --check tests examples sentry_sdk".split())
122+
session.run(*"mypy examples sentry_sdk".split())
123+
124+
125+
import os
126+
travis_python = os.environ.get("TRAVIS_PYTHON_VERSION")
127+
128+
if travis_python:
129+
@nox.session(python=travis_python)
130+
def travis_test(session):
131+
for name, f in globals().items():
132+
if name.startswith(f"test-{travis_python}"):
133+
f(session)
80134

81135

82-
generate_sessions(locals())
136+
generate_test_sessions()

scripts/runnox.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
if [ -n "$NOXPATH" ]; then
5+
true
6+
elif which nox &> /dev/null; then
7+
NOXPATH=nox
8+
else
9+
NOXPATH=./.venv/bin/nox
10+
fi
11+
12+
# Usage: sh scripts/runtox.sh py3.7 <pytest-args>
13+
# Runs all environments with substring py3.7 and the given arguments for pytest
14+
15+
if [ -n "$1" ]; then
16+
searchstring="$1"
17+
elif [ -n "$TRAVIS_PYTHON_VERSION" ]; then
18+
searchstring="$(echo py$TRAVIS_PYTHON_VERSION | sed -e 's/pypypy/pypy/g' -e 's/-dev//g')"
19+
elif [ -n "$AZURE_PYTHON_VERSION" ]; then
20+
searchstring="$(echo py$AZURE_PYTHON_VERSION | sed -e 's/pypypy/pypy/g' -e 's/-dev//g')"
21+
if [ "$searchstring" = pypy2 ]; then
22+
searchstring=pypy
23+
fi
24+
fi
25+
26+
exec $NOXPATH -k "$searchstring"

scripts/travis-install-nox.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -exo pipefail
4+
5+
# Linux Setup
6+
# Even when testing on Python 2, we need Python 3 for Nox. This detects if
7+
# we're in one of the Travis Python 2 sessions and sets up the Python 3 install
8+
# for Nox.
9+
# Taken from urllib3/urllib3
10+
if ! python3 -m pip --version; then
11+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
12+
sudo python3 get-pip.py
13+
# https://github.com/theacodes/nox/issues/328
14+
sudo python3 -m pip install nox==2019.11.9
15+
else
16+
# We're not in "dual Python" mode, so we can just install Nox normally.
17+
python3 -m pip install nox
18+
fi

tox.ini

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ envlist =
5656
{py3.7,py3.8}-tornado-{5,6}
5757

5858
{py3.4,py3.5,py3.6,py3.7,py3.8}-trytond-{4.6,4.8,5.0}
59-
{py3.5,py3.6,py3.7,py3.8}-trytond-{5.2}
60-
{py3.6,py3.7,py3.8}-trytond-{5.4}
59+
{py3.5,py3.6,py3.7,py3.8}-trytond-5.2
60+
{py3.6,py3.7,py3.8}-trytond-5.4
6161

6262
{py2.7,py3.8}-requests
6363

@@ -98,6 +98,7 @@ deps =
9898
django-dev: git+https://github.com/django/django.git#egg=Django
9999

100100
flask: flask-login
101+
flask: blinker>=1.1
101102
flask-0.11: Flask>=0.11,<0.12
102103
flask-0.12: Flask>=0.12,<0.13
103104
flask-1.0: Flask>=1.0,<1.1
@@ -220,10 +221,6 @@ passenv =
220221
SENTRY_PYTHON_TEST_POSTGRES_USER
221222
SENTRY_PYTHON_TEST_POSTGRES_NAME
222223
usedevelop = True
223-
extras =
224-
flask: flask
225-
bottle: bottle
226-
falcon: falcon
227224

228225
basepython =
229226
py2.7: python2.7

0 commit comments

Comments
 (0)