Skip to content

Commit 3df2b5e

Browse files
authored
Merge pull request #267 from warsaw/validateCoverage
Make enabling coverage a little easier
2 parents a5c0abb + 2a5e073 commit 3df2b5e

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2016 LinkedIn Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.linkedin.gradle.python.extension;
17+
18+
public class CoverageExtension {
19+
private boolean run;
20+
21+
public boolean isRun() {
22+
return run;
23+
}
24+
25+
public void setRun(boolean run) {
26+
this.run = run;
27+
}
28+
}

pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/plugin/internal/ValidationPlugin.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.linkedin.gradle.python.PythonExtension;
1919
import com.linkedin.gradle.python.extension.MypyExtension;
20+
import com.linkedin.gradle.python.extension.CoverageExtension;
2021
import com.linkedin.gradle.python.tasks.AbstractPythonMainSourceDefaultTask;
2122
import com.linkedin.gradle.python.tasks.AbstractPythonTestSourceDefaultTask;
2223
import com.linkedin.gradle.python.tasks.CheckStyleGeneratorTask;
@@ -72,8 +73,20 @@ public void apply(final Project project) {
7273
*
7374
* This uses the ``setup.cfg`` if present to configure py.test.
7475
*/
76+
CoverageExtension cov = ExtensionUtils.maybeCreate(project, "coverage", CoverageExtension.class);
7577
project.getTasks().create(TASK_COVERAGE.getValue(), PyCoverageTask.class,
76-
task -> task.onlyIf(it -> project.file(settings.testDir).exists()));
78+
task -> task.onlyIf(it -> project.file(settings.testDir).exists()
79+
/* The test suite and other environments run
80+
* the coverage task explicitly, so check
81+
* whether the flag is set *or* its been
82+
* explicitly invoked.
83+
*/
84+
&& (cov.isRun() || project.getGradle().getStartParameter().getTaskNames().contains("coverage"))
85+
));
86+
87+
// Make task "check" depend on coverage task.
88+
project.getTasks().getByName(TASK_CHECK.getValue())
89+
.dependsOn(project.getTasks().getByName(TASK_COVERAGE.getValue()));
7790

7891
/*
7992
* Run flake8.
@@ -92,7 +105,7 @@ public void apply(final Project project) {
92105
project.getTasks().create(TASK_MYPY.getValue(), MypyTask.class,
93106
task -> task.onlyIf(it -> project.file(settings.srcDir).exists() && mypy.isRun()));
94107

95-
// Make task "check" depend on mypy task
108+
// Make task "check" depend on mypy task.
96109
project.getTasks().getByName(TASK_CHECK.getValue())
97110
.dependsOn(project.getTasks().getByName(TASK_MYPY.getValue()));
98111

0 commit comments

Comments
 (0)