-
Notifications
You must be signed in to change notification settings - Fork 18
/
noxfile.py
157 lines (115 loc) · 4.63 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
if __name__ == "__main__":
__import__("sys").exit(
"Do not execute this file directly. Use nox instead, it will know how to handle this file"
)
import os
import pathlib
import shutil
import nox
from nox.sessions import Session
nox.options.sessions = ["black", "flake8", "mypy", "test_contracts"]
python_paths = [
"contracts/tests/",
"noxfile.py",
]
requirements_as_constraints = ["-c", "requirements.txt"]
nox.options.error_on_external_run = True
nox.options.reuse_existing_virtualenvs = True
def install_ganache(session: Session) -> None:
"""install ganache-cli"""
session.install("nodeenv")
assert session.bin is not None
nodeenv_dir = pathlib.Path(session.bin).parent.joinpath("node")
bindir = nodeenv_dir.joinpath("bin").absolute()
ganache_cli = bindir.joinpath("ganache-cli")
os.environ["PATH"] = str(bindir) + os.pathsep + os.environ["PATH"]
session.env["PATH"] = str(bindir) + os.pathsep + session.env["PATH"]
if not ganache_cli.exists():
if nodeenv_dir.exists():
shutil.rmtree(nodeenv_dir)
session.run("nodeenv", str(nodeenv_dir))
session.run(
str(bindir.joinpath("npm")),
"install",
"-g",
silent=True,
external=True,
)
def install_prettier(session: Session) -> None:
"""install prettier"""
session.install("nodeenv")
assert session.bin is not None
nodeenv_dir = pathlib.Path(session.bin).parent.joinpath("node")
bindir = nodeenv_dir.joinpath("bin").absolute()
prettier_cli = bindir.joinpath("prettier")
os.environ["PATH"] = str(bindir) + os.pathsep + os.environ["PATH"]
session.env["PATH"] = str(bindir) + os.pathsep + session.env["PATH"]
if not prettier_cli.exists():
if nodeenv_dir.exists():
shutil.rmtree(nodeenv_dir)
session.run("nodeenv", str(nodeenv_dir))
for pkg in ["[email protected]", "[email protected]"]:
session.run(
str(bindir.joinpath("npm")), "install", "-g", pkg, silent=True, external=True
)
def fix_requirements(session: Session) -> None:
"""remove extra requirements, because otherwise pip can't use this file as a constraints file
anymore"""
session.run("sed", "-i", r"s/\[.*\]//", "requirements.txt", external=True)
@nox.session
def update_requirements(session: Session) -> None:
session.install("pip-tools")
session.run("pip-compile", "requirements.in")
fix_requirements(session)
@nox.session
def upgrade_requirements(session: Session) -> None:
session.install("pip-tools")
session.run("pip-compile", "-U", "requirements.in")
fix_requirements(session)
@nox.session
def black(session: Session) -> None:
session.install("black", *requirements_as_constraints)
session.run("black", "--check", "--diff", *python_paths)
@nox.session
def flake8(session: Session) -> None:
session.install("flake8", "flake8-import-order", *requirements_as_constraints)
session.run("flake8", *python_paths)
@nox.session
def mypy(session: Session) -> None:
session.install("mypy", *requirements_as_constraints)
session.install("-r", "requirements.txt")
session.run("mypy", *python_paths)
@nox.session
def prettier(session: Session) -> None:
install_prettier(session)
session.run("prettier", "--check", ".", external=True)
@nox.session
def test_contracts(session: Session) -> None:
session.install("-r", "requirements.txt")
install_ganache(session)
session.chdir("contracts")
session.run("brownie", "compile")
session.run("brownie", "test")
@nox.session
def build_dapp(session: Session) -> None:
session.install("nodeenv")
assert session.bin is not None
nodeenv_dir = pathlib.Path(session.bin).parent.joinpath("node")
bindir = nodeenv_dir.joinpath("bin").absolute()
os.environ["PATH"] = str(bindir) + os.pathsep + os.environ["PATH"]
session.env["PATH"] = str(bindir) + os.pathsep + session.env["PATH"]
if not nodeenv_dir.exists():
session.run("nodeenv", str(nodeenv_dir))
session.cd("example/")
npm = str(bindir.joinpath("npm"))
session.run(npm, "install", external=True, silent=True)
session.run(npm, "run", "build", external=True, silent=True)
session.cd("..")
session.env["BINDIR"] = pathlib.Path("example/dist").absolute()
session.cd("shuttermint")
session.run("make", "wasm", external=True, silent=False)
session.cd("..")
# Alas, the following doesn't work
# session.run(npm, "install", "-g", "serve", external=True, silent=True)
# session.run("serve", "-s", "example/dist/", external=True)