forked from astronomer/astro-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
117 lines (91 loc) · 3.38 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
"""Nox automation definitions."""
import pathlib
import nox
nox.options.sessions = ["dev"]
nox.options.reuse_existing_virtualenvs = True
@nox.session(python="3.9")
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]")
session.install("-e", ".[tests]")
@nox.session(python=["3.7", "3.8", "3.9"])
@nox.parametrize("airflow", ["2.2.5", "2.3"])
def test(session: nox.Session, airflow) -> None:
"""Run both unit and integration tests."""
session.install("-e", ".[all]")
session.install("-e", ".[tests]")
# Log all the installed dependencies
session.log("Installed Dependencies:")
session.run("pip3", "freeze")
session.run("airflow", "db", "init")
session.run("pytest", *session.posargs)
@nox.session(python=["3.8"])
def type_check(session: nox.Session) -> None:
"""Run MyPy checks."""
session.install("-e", ".[all]")
session.install("-e", ".[tests]")
session.run("mypy", "--version")
session.run("mypy")
@nox.session()
@nox.parametrize(
"extras",
[
("postgres-amazon", {"include": ["postgres", "amazon"]}),
("snowflake-amazon", {"include": ["snowflake", "amazon"]}),
("sqlite", {"include": ["sqlite"]}),
],
)
def test_examples_by_dependency(session: nox.Session, extras):
_, extras = extras
pypi_deps = ",".join(extras["include"])
pytest_options = " and ".join(extras["include"])
pytest_options = " and not ".join([pytest_options, *extras.get("exclude", [])])
pytest_args = ["-k", pytest_options]
session.install("-e", f".[{pypi_deps}]")
session.install("-e", ".[tests]")
session.run("airflow", "db", "init")
session.run("pytest", "tests/test_example_dags.py", *pytest_args, *session.posargs)
@nox.session()
def lint(session: nox.Session) -> None:
"""Run linters."""
session.install("pre-commit")
if session.posargs:
args = [*session.posargs, "--all-files"]
else:
args = ["--all-files", "--show-diff-on-failure"]
session.run("pre-commit", "run", *args)
@nox.session()
def build(session: nox.Session) -> None:
"""Build release artifacts."""
session.install("build")
# TODO: Automate version bumping, Git tagging, and more?
dist = pathlib.Path("dist")
if dist.exists() and next(dist.iterdir(), None) is not None:
session.error(
"There are files in dist/. Remove them and try again. "
"You can use `git clean -fxdi -- dist` command to do this."
)
dist.mkdir(exist_ok=True)
session.run("python", "-m", "build", *session.posargs)
@nox.session(python="3.9")
def build_docs(session: nox.Session) -> None:
"""Build release artifacts."""
session.install("sphinx")
session.install("sphinx-view")
session.install("sphinx-autoapi")
session.install("sphinx-rtd-theme")
session.install("myst-parser")
# session.install("-e", ".[google]")
session.chdir("./docs")
session.run("make", "html")
@nox.session()
def release(session: nox.Session) -> None:
"""Publish a release."""
session.install("twine")
# TODO: Better artifact checking.
session.run("twine", "check", *session.posargs)
session.run("twine", "upload", *session.posargs)