forked from astronomer/astronomer-cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
80 lines (61 loc) · 2.29 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
"""Nox automation definitions."""
import os
from pathlib import Path
import nox
nox.options.sessions = ["dev"]
nox.options.reuse_existing_virtualenvs = True
os.environ[
"AIRFLOW__CORE__ALLOWED_DESERIALIZATION_CLASSES"
] = "airflow.* astro.* cosmos.*"
@nox.session(python="3.10")
def dev(session: nox.Session) -> None:
"""Create a dev environment with everything installed.
This is useful for setting up IDE for autocompletion etc. Point the
development environment to ``.nox/dev``.
"""
session.install("nox")
session.install("-e", ".[all,tests,docker,kubernetes]")
def _expand_env_vars(file_path: Path):
"""Expand environment variables in the given file."""
with file_path.open() as fp:
yaml_with_env = os.path.expandvars(fp.read())
with file_path.open("w") as fp:
fp.write(yaml_with_env)
@nox.session(python=["3.8", "3.9", "3.10"])
@nox.parametrize("airflow", ["2.4", "2.5"])
def test(session: nox.Session, airflow) -> None:
"""Run both unit and integration tests."""
session.run("echo", "$PWD")
env = {
"AIRFLOW_HOME": f"~/airflow-{airflow}-python-{session.python}",
"AIRFLOW__CORE__ALLOWED_DESERIALIZATION_CLASSES": "airflow\\.* astro\\.* cosmos\\.*",
}
session.install(f"apache-airflow=={airflow}")
session.install("-e", ".[all,tests,docker,kubernetes]")
# Log all the installed dependencies
session.log("Installed Dependencies:")
session.run("pip3", "freeze")
test_connections_file = Path("test-connections.yaml")
if test_connections_file.exists():
_expand_env_vars(test_connections_file)
session.run("airflow", "db", "init", env=env)
# Since pytest is not installed in the nox session directly, we need to set `external=true`.
session.run(
"pytest",
"-vv",
*session.posargs,
env=env,
external=True,
)
@nox.session(python=["3.8"])
def type_check(session: nox.Session) -> None:
"""Run MyPy checks."""
session.install("-e", ".[all,tests,docker,kubernetes]")
session.run("mypy", "--version")
session.run("mypy", "cosmos")
@nox.session(python="3.9")
def build_docs(session: nox.Session) -> None:
"""Build release artifacts."""
session.install("-e", ".[docs]")
session.chdir("./docs")
session.run("make", "html")