-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnoxfile.py
143 lines (117 loc) · 4.79 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
"""Nox Configuration for Jobmon."""
import glob
import os
from pathlib import Path
import shutil
import tempfile
from time import sleep
import nox
from nox.sessions import Session
src_locations = ["jobmon_client/src", "jobmon_core/src", "jobmon_server/src"]
test_locations = ["tests"]
python = "3.10"
@nox.session(python=python, venv_backend="conda")
def tests(session: Session) -> None:
"""Run the test suite."""
session.install("pytest", "pytest-xdist", "pytest-cov", "mock", "filelock", "pytest-mock")
session.install("-e", "./jobmon_core", "-e", "./jobmon_client", "-e", "./jobmon_server")
args = session.posargs or test_locations
session.run(
"coverage",
"run",
"-m",
"pytest",
*args,
env={"SQLALCHEMY_WARN_20": "1"}
)
@nox.session(python=python, venv_backend="conda")
def lint(session: Session) -> None:
"""Lint code using various plugins.
flake8 - a Python library that wraps PyFlakes, pycodestyle and McCabe script.
flake8-import-order - checks the ordering of your imports.
flake8-docstrings - extension for flake8 which uses pydocstyle to check docstrings.
flake8-annotations -is a plugin for Flake8 that detects the absence of PEP 3107-style
function annotations and PEP 484-style type comments.
"""
args = session.posargs or src_locations
# TODO: work these in over time?
# "darglint",
# "flake8-bandit"
session.install(
"flake8",
"flake8-annotations",
"flake8-import-order",
"flake8-docstrings",
"flake8-black"
)
session.run("flake8", *args)
@nox.session(python=python, venv_backend="conda")
def black(session):
args = session.posargs or src_locations + test_locations
session.install("black")
session.run("black", *args)
@nox.session(python=python, venv_backend="conda")
def typecheck(session: Session) -> None:
"""Type check code."""
args = session.posargs or src_locations
session.install("mypy", "types-Flask", "types-requests", "types-PyMySQL", "types-filelock",
"types-PyYAML", "types-tabulate", "types-psutil", "types-Flask-Cors",
"types-sqlalchemy-utils", "types-setuptools", "types-mysqlclient")
session.install("-e", "./jobmon_core", "-e", "./jobmon_client", "-e", "./jobmon_server")
session.run("mypy", "--explicit-package-bases", *args)
@nox.session(python=python, venv_backend="conda")
def schema_diagram(session: Session) -> None:
session.install("-e", "./jobmon_server")
outpath = Path(__file__).parent / "docsource" / "developers_guide" / "diagrams" / "erd.svg"
with tempfile.TemporaryDirectory() as tmpdir:
session.chdir(tmpdir)
session.run(
"jobmon_server", "init_db",
env={"JOBMON__DB__SQLALCHEMY_DATABASE_URI": "sqlite:///jobmon.db"}
)
session.run("docker", "pull", "schemacrawler/schemacrawler", external=True)
session.run(
"docker",
"run",
"--mount", f"type=bind,source={tmpdir},target=/home/schcrwlr/share",
"--rm", "-it", "schemacrawler/schemacrawler",
"/opt/schemacrawler/bin/schemacrawler.sh",
"--server=sqlite",
"--database=share/jobmon.db",
"--info-level=standard",
"--portable-names",
"--command", "schema",
"--output-format=svg",
"--output-file=share/erd.svg",
"--title", "Jobmon Database",
external=True
)
session.run("cp", "erd.svg", str(outpath))
@nox.session(python=python, venv_backend="conda")
def build(session: Session) -> None:
args = session.posargs or src_locations
session.install("build")
for src_dir in args:
namespace_dir = str(Path(src_dir).parent)
session.run("python", "-m", "build", "--outdir", "dist", namespace_dir)
@nox.session(python=python, venv_backend="conda")
def clean(session: Session) -> None:
dirs_to_remove = ['out', 'dist', 'build', ".eggs",
'.pytest_cache', 'docsource/api', '.mypy_cache']
egg_info = glob.glob("jobmon_*/src/*.egg-info")
dirs_to_remove.extend(egg_info)
builds = glob.glob("jobmon_*/build")
dirs_to_remove.extend(builds)
for path in dirs_to_remove:
if os.path.exists(path):
shutil.rmtree(path)
files_to_remove = ['test_report.xml', '.coverage']
for file in files_to_remove:
if os.path.exists(file):
os.remove(file)
@nox.session(python=python, venv_backend="conda")
def build_gui_test_env(session: Session) -> None:
session.conda_install("mysqlclient", "--channel", "conda-forge")
if os.path.exists("/tmp/tests.sqlite"):
os.remove("/tmp/tests.sqlite")
session.install("-e", "./jobmon_core", "-e", "./jobmon_client", "-e", "./jobmon_server")