meltano

Форк
0
/
noxfile.py 
175 строк · 4.5 Кб
1
"""Nox configuration.
2

3
- Run `nox -l` to list the sessions Nox can run.
4
- Run `nox -t lint` to run linting.
5
- Run `nox -t test` to run tests.
6
- Run `nox` to run all sessions.
7
- Run `nox -s <session name>` to run a particular session.
8
"""
9

10
from __future__ import annotations
11

12
import os
13
import sys
14
import typing as t
15
from pathlib import Path
16
from random import randint
17

18
if t.TYPE_CHECKING:
19
    from nox import Session
20

21
try:
22
    from nox_poetry import session as nox_session
23
except ImportError:
24
    raise SystemExit(
25
        "Nox failed to import the 'nox-poetry' package. Please install it "  # noqa: EM102
26
        f"using the following command: {sys.executable} -m pip install nox-poetry",
27
    ) from None
28

29
# NOTE: The module docstring above is printed when `nox -l` is run.
30

31
# Dependencies for tests and type checking are defined in `pyproject.toml`, and
32
# locked in `poetry.lock`. The various Nox sessions defined here install the
33
# subset of them they require.
34

35
# We use `nox-poetry` to ensure the version installed is consistent with
36
# `poetry.lock`. The single source of truth for our Python test and type checking
37
# dependencies is `pyproject.toml`. Other linting and checks are performed by
38
# `pre-commit`, where each check specifies its own dependencies. There should be
39
# no duplicated dependencies between `pyproject.toml` and
40
# `.pre-commit-config.yaml`.
41

42
root_path = Path(__file__).parent
43
python_versions = ("3.8", "3.9", "3.10", "3.11", "3.12")
44
main_python_version = "3.10"
45
pytest_deps = (
46
    "backoff",
47
    "colorama",  # colored output in Windows
48
    "freezegun",
49
    "hypothesis",
50
    "mock",
51
    "moto",
52
    "pytest",
53
    "pytest-asyncio",
54
    "pytest-cov",
55
    "pytest-docker",
56
    "pytest-httpserver",
57
    "pytest-order",
58
    "pytest-randomly",
59
    "pytest-rerunfailures",
60
    "pytest-xdist",
61
    "requests-mock",
62
    "pytest-structlog",
63
)
64

65

66
def _run_pytest(session: Session) -> None:
67
    random_seed = randint(0, 2**32 - 1)  # noqa: S311, WPS432
68
    args = session.posargs or ("tests/",)
69
    try:
70
        session.env.update(
71
            {
72
                "COVERAGE_RCFILE": str(root_path / "pyproject.toml"),
73
                "COVERAGE_FILE": str(
74
                    root_path / f".coverage.{random_seed:010}.{session.name}",
75
                ),
76
                "NOX_CURRENT_SESSION": "tests",
77
            },
78
        )
79
        session.run(
80
            "pytest",
81
            "--cov=meltano",
82
            "--cov=tests",
83
            f"--randomly-seed={random_seed}",
84
            *args,
85
        )
86
    finally:
87
        if session.interactive:
88
            session.notify("coverage", posargs=[])
89

90

91
@nox_session(
92
    name="pytest",
93
    python=python_versions,
94
    tags=("test", "pytest"),
95
)
96
def pytest_meltano(session: Session) -> None:
97
    """Run pytest to test Meltano.
98

99
    Args:
100
        session: Nox session.
101
    """
102
    backend_db = os.environ.get("PYTEST_BACKEND", "sqlite")
103
    extras = ["azure", "gcs", "s3", "uv"]
104

105
    if backend_db == "mssql":
106
        extras.append("mssql")
107
    elif backend_db == "postgresql":
108
        extras.append("psycopg2")
109
    elif backend_db == "postgresql_psycopg3":
110
        extras.append("postgres")
111

112
    session.install(
113
        f".[{','.join(extras)}]",
114
        *pytest_deps,
115
    )
116
    _run_pytest(session)
117

118

119
@nox_session(python=main_python_version)
120
def coverage(session: Session) -> None:
121
    """Combine and report previously generated coverage data.
122

123
    Args:
124
        session: Nox session.
125
    """
126
    args = session.posargs or ("report",)
127

128
    session.install("coverage[toml]")
129

130
    if not session.posargs and any(Path().glob(".coverage.*")):
131
        session.run("coverage", "combine")
132

133
    session.run("coverage", *args)
134

135

136
@nox_session(
137
    name="pre-commit",
138
    python=main_python_version,
139
    tags=("lint",),
140
)
141
def pre_commit(session: Session) -> None:
142
    """Run pre-commit linting and auto-fixes.
143

144
    Args:
145
        session: Nox session.
146
    """
147
    args = session.posargs or ("run", "--all-files")
148
    session.install("pre-commit")
149
    session.run("pre-commit", *args)
150

151

152
@nox_session(
153
    python=main_python_version,
154
    tags=("lint",),
155
)
156
def mypy(session: Session) -> None:
157
    """Run mypy type checking.
158

159
    Args:
160
        session: Nox session.
161
    """
162
    session.install(
163
        ".[mssql,azure,gcs,s3,uv]",
164
        "boto3-stubs",
165
        "mypy",
166
        "types-croniter",
167
        "types-python-dateutil",
168
        "types-jsonschema",
169
        "types-psutil",
170
        "types-python-slugify",
171
        "types-PyYAML",
172
        "types-requests",
173
        "types-tabulate",
174
    )
175
    session.run("mypy", *session.posargs)
176

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.