forked from CU-DBMI/smartsheet-notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.cue
228 lines (224 loc) · 5.27 KB
/
project.cue
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package main
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
dagger.#Plan & {
client: {
filesystem: {
"./": read: contents: dagger.#FS
"./smartsheet-notebooks": write: contents: actions.clean.black.export.directories."/workdir/smartsheet-notebooks"
"./project.cue": write: contents: actions.clean.cue.export.files."/workdir/project.cue"
}
}
python_version: string | *"3.9"
poetry_version: string | *"1.1.13"
actions: {
// referential build for base python image
_python_pre_build: docker.#Build & {
steps: [
docker.#Pull & {
source: "python:" + python_version
},
docker.#Run & {
command: {
name: "mkdir"
args: ["/workdir"]
}
},
docker.#Copy & {
contents: client.filesystem."./".read.contents
source: "./pyproject.toml"
dest: "/workdir/pyproject.toml"
},
docker.#Copy & {
contents: client.filesystem."./".read.contents
source: "./poetry.lock"
dest: "/workdir/poetry.lock"
},
docker.#Run & {
workdir: "/workdir"
command: {
name: "pip"
args: ["install", "--no-cache-dir", "poetry==" + poetry_version]
}
},
docker.#Set & {
config: {
env: ["POETRY_VIRTUALENVS_CREATE"]: "false"
}
},
docker.#Run & {
workdir: "/workdir"
command: {
name: "poetry"
args: ["install", "--no-interaction", "--no-ansi"]
}
},
]
}
// python build for actions in this plan
_python_build: docker.#Build & {
steps: [
docker.#Copy & {
input: _python_pre_build.output
contents: client.filesystem."./".read.contents
source: "./"
dest: "/workdir"
},
]
}
// cuelang pre build
_cue_pre_build: docker.#Build & {
steps: [
docker.#Pull & {
source: "golang:latest"
},
docker.#Run & {
command: {
name: "mkdir"
args: ["/workdir"]
}
},
docker.#Run & {
command: {
name: "go"
args: ["install", "cuelang.org/go/cmd/cue@latest"]
}
},
]
}
// cuelang build for actions in this plan
_cue_build: docker.#Build & {
steps: [
docker.#Copy & {
input: _cue_pre_build.output
contents: client.filesystem."./".read.contents
source: "./project.cue"
dest: "/workdir/project.cue"
},
]
}
// applied code and/or file formatting
clean: {
// remove jupyter notebook output data
remove_jupyter_output: docker.#Run & {
input: _python_build.output
workdir: "/workdir"
command: {
name: "find"
args: ["/workdir/smartsheet-notebooks", "-name", "*.ipynb",
"-exec", "poetry", "run", "python", "-m", "jupyter", "nbconvert",
"--clear-output", "--inplace",
"{}", "+"]
}
}
// sort python imports with isort
isort: docker.#Run & {
input: remove_jupyter_output.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "isort", "smartsheet-notebooks/"]
}
}
// code style formatting with black
black: docker.#Run & {
input: isort.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "black", "smartsheet-notebooks/"]
}
export: {
directories: {
"/workdir/smartsheet-notebooks": _
}
}
}
// code formatting for cuelang
cue: docker.#Run & {
input: _cue_build.output
workdir: "/workdir"
command: {
name: "cue"
args: ["fmt", "/workdir/project.cue"]
}
export: {
files: "/workdir/project.cue": _
}
}
}
// lint
lint: {
// mypy static type check
mypy: {
output: run.output
// mypy has trouble with dashed-name "-" directories,
// so we copy the contents for mypy focus to similar dir
copy: docker.#Run & {
input: _python_build.output
workdir: "/workdir"
command: {
name: "cp"
args: ["-r", "/workdir/smartsheet-notebooks/", "/workdir/smartsheet_notebooks/"]
}
}
// actual mypy check
run: docker.#Run & {
input: copy.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "mypy", "smartsheet_notebooks/", "--ignore-missing-imports"]
}
}
}
// isort (imports) formatting check
isort: docker.#Run & {
input: mypy.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "isort", "smartsheet-notebooks/", "--check", "--diff"]
}
}
// black formatting check
black: docker.#Run & {
input: isort.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "black", "smartsheet-notebooks/", "--check"]
}
}
// pylint checks
pylint: docker.#Run & {
input: black.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "pylint", "smartsheet-notebooks/"]
}
}
// safety security vulnerabilities check
safety: docker.#Run & {
input: pylint.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "safety", "check"]
}
}
// bandit security vulnerabilities check
bandit: docker.#Run & {
input: safety.output
workdir: "/workdir"
command: {
name: "poetry"
args: ["run", "nbqa", "bandit", "smartsheet-notebooks/", "-r"]
}
}
}
}
}