16
16
package com .linkedin .gradle .python .plugin .internal ;
17
17
18
18
import com .linkedin .gradle .python .PythonExtension ;
19
+ import com .linkedin .gradle .python .extension .BlackExtension ;
20
+ import com .linkedin .gradle .python .extension .IsortExtension ;
19
21
import com .linkedin .gradle .python .extension .MypyExtension ;
20
22
import com .linkedin .gradle .python .extension .CoverageExtension ;
21
23
import com .linkedin .gradle .python .tasks .AbstractPythonMainSourceDefaultTask ;
22
24
import com .linkedin .gradle .python .tasks .AbstractPythonTestSourceDefaultTask ;
25
+ import com .linkedin .gradle .python .tasks .BlackTask ;
23
26
import com .linkedin .gradle .python .tasks .CheckStyleGeneratorTask ;
24
27
import com .linkedin .gradle .python .tasks .Flake8Task ;
25
28
import com .linkedin .gradle .python .tasks .MypyTask ;
29
+ import com .linkedin .gradle .python .tasks .IsortTask ;
26
30
import com .linkedin .gradle .python .tasks .PyCoverageTask ;
27
31
import com .linkedin .gradle .python .tasks .PyTestTask ;
28
32
import com .linkedin .gradle .python .util .ExtensionUtils ;
32
36
import org .gradle .api .logging .Logger ;
33
37
import org .gradle .api .logging .Logging ;
34
38
39
+ import static com .linkedin .gradle .python .util .StandardTextValues .TASK_BLACK ;
35
40
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_CHECK ;
36
41
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_CHECKSTYLE ;
37
42
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_COVERAGE ;
38
43
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_FLAKE ;
39
44
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_INSTALL_BUILD_REQS ;
40
45
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_INSTALL_PROJECT ;
41
46
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_MYPY ;
47
+ import static com .linkedin .gradle .python .util .StandardTextValues .TASK_ISORT ;
42
48
import static com .linkedin .gradle .python .util .StandardTextValues .TASK_PYTEST ;
43
49
44
50
public class ValidationPlugin implements Plugin <Project > {
@@ -112,7 +118,7 @@ public void apply(final Project project) {
112
118
/*
113
119
* Run mypy.
114
120
*
115
- * This uses the mypy.ini file if present to configure mypy.
121
+ * This uses the setup.cfg (or mypy.ini) file if present to configure mypy.
116
122
*/
117
123
MypyExtension mypy = ExtensionUtils .maybeCreate (project , "mypy" , MypyExtension .class );
118
124
project .getTasks ().create (TASK_MYPY .getValue (), MypyTask .class ,
@@ -122,6 +128,28 @@ public void apply(final Project project) {
122
128
project .getTasks ().getByName (TASK_CHECK .getValue ())
123
129
.dependsOn (project .getTasks ().getByName (TASK_MYPY .getValue ()));
124
130
131
+ /*
132
+ * Run isort.
133
+ */
134
+ IsortExtension isort = ExtensionUtils .maybeCreate (project , "isort" , IsortExtension .class );
135
+ project .getTasks ().create (TASK_ISORT .getValue (), IsortTask .class ,
136
+ task -> task .onlyIf (it -> project .file (settings .srcDir ).exists () && isort .isRun ()));
137
+
138
+ // Make task "check" depend on isort task.
139
+ project .getTasks ().getByName (TASK_CHECK .getValue ())
140
+ .dependsOn (project .getTasks ().getByName (TASK_ISORT .getValue ()));
141
+
142
+ /*
143
+ * Run black.
144
+ */
145
+ BlackExtension black = ExtensionUtils .maybeCreate (project , "black" , BlackExtension .class );
146
+ project .getTasks ().create (TASK_BLACK .getValue (), BlackTask .class ,
147
+ task -> task .onlyIf (it -> project .file (settings .srcDir ).exists () && black .isRun ()));
148
+
149
+ // Make task "check" depend on black task.
150
+ project .getTasks ().getByName (TASK_CHECK .getValue ())
151
+ .dependsOn (project .getTasks ().getByName (TASK_BLACK .getValue ()));
152
+
125
153
/*
126
154
* Create checkstyle styled report from flake
127
155
*/
0 commit comments