forked from meltano/meltano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
170 lines (142 loc) · 4.35 KB
/
noxfile.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""Nox configuration.
- Run `nox -l` to list the sessions Nox can run.
- Run `nox -t lint` to run linting.
- Run `nox -t test` to run tests.
- Run `nox` to run all sessions.
- Run `nox -s <session name>` to run a particular session.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
from random import randint
from nox import Session
try:
from nox_poetry import session as nox_session
except ImportError:
raise SystemExit(
"Nox failed to import the 'nox-poetry' package. Please install it "
f"using the following command: {sys.executable} -m pip install nox-poetry",
) from None
# NOTE: The module docstring above is printed when `nox -l` is run.
# Dependencies for tests and type checking are defined in `pyproject.toml`, and
# locked in `poetry.lock`. The various Nox sessions defined here install the
# subset of them they require.
# We use `nox-poetry` to ensure the version installed is consistent with
# `poetry.lock`. The single source of truth for our Python test and type checking
# dependencies is `pyproject.toml`. Other linting and checks are performed by
# `pre-commit`, where each check specifies its own dependencies. There should be
# no duplicated dependencies between `pyproject.toml` and
# `.pre-commit-config.yaml`.
root_path = Path(__file__).parent
python_versions = ("3.8", "3.9", "3.10", "3.11")
main_python_version = "3.10"
pytest_deps = (
"backoff",
"colorama", # colored output in Windows
"freezegun",
"hypothesis",
"mock",
"moto",
"pytest",
"pytest-aiohttp",
"pytest-asyncio",
"pytest-cov",
"pytest-docker",
"pytest-httpserver",
"pytest-order",
"pytest-randomly",
"pytest-xdist",
"requests-mock",
"pytest-structlog",
)
def _run_pytest(session: Session) -> None:
random_seed = randint(0, 2**32 - 1) # noqa: S311, WPS432
args = session.posargs or ("tests/",)
try:
session.env.update(
{
"COVERAGE_RCFILE": str(root_path / "pyproject.toml"),
"COVERAGE_FILE": str(
root_path / f".coverage.{random_seed:010}.{session.name}",
),
"NOX_CURRENT_SESSION": "tests",
},
)
session.run(
"pytest",
"--cov=meltano",
"--cov=tests",
f"--randomly-seed={random_seed}",
*args,
)
finally:
if session.interactive:
session.notify("coverage", posargs=[])
@nox_session(
name="pytest",
python=python_versions,
tags=("test", "pytest"),
)
def pytest_meltano(session: Session) -> None:
"""Run pytest to test Meltano.
Args:
session: Nox session.
"""
backend_db = os.environ.get("PYTEST_BACKEND", "sqlite")
extras = ["azure", "gcs", "s3"]
if backend_db == "mssql":
extras.append("mssql")
elif backend_db == "postgresql":
extras.append("psycopg2")
elif backend_db == "postgresql_psycopg3":
extras.append("postgres")
session.install(f".[{','.join(extras)}]", *pytest_deps)
_run_pytest(session)
@nox_session(python=main_python_version)
def coverage(session: Session) -> None:
"""Combine and report previously generated coverage data.
Args:
session: Nox session.
"""
args = session.posargs or ("report",)
session.install("coverage[toml]")
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args)
@nox_session(
name="pre-commit",
python=main_python_version,
tags=("lint",),
)
def pre_commit(session: Session) -> None:
"""Run pre-commit linting and auto-fixes.
Args:
session: Nox session.
"""
args = session.posargs or ("run", "--all-files")
session.install("pre-commit")
session.run("pre-commit", *args)
@nox_session(
python=main_python_version,
tags=("lint",),
)
def mypy(session: Session) -> None:
"""Run mypy type checking.
Args:
session: Nox session.
"""
session.install(
".",
"boto3-stubs",
"mypy",
"types-croniter",
"types-python-dateutil",
"types-jsonschema",
"types-psutil",
"types-python-slugify",
"types-PyYAML",
"types-requests",
"types-tabulate",
)
session.run("mypy", *session.posargs)