8000 Refactor MypyTask and MypyExtension for local customizations · warsaw/pygradle@23af764 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 30, 2023. It is now read-only.

Commit 23af764

Browse files
author
Barry Warsaw
committed
Refactor MypyTask and MypyExtension for local customizations
If and when python/mypy#7219 lands, we will have the ability to tell mypy to traverse into PEP 420 namespace packages. In order to preserve backward compatibility, the MypyExtension now allows clients to set the mypy command line arguments, but if they don't it will use the old command line of just passing the source directory.
1 parent da64eb0 commit 23af764

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/extension/MypyExtension.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@
1515
*/
1616
package com.linkedin.gradle.python.extension;
1717

18+
import org.gradle.api.Project;
19+
import com.linkedin.gradle.python.util.ExtensionUtils;
20+
21+
1822
public class MypyExtension {
1923
private boolean run;
24+
private String[] arguments = null;
25+
private String srcDir;
26+
27+
public MypyExtension(Project project) {
28+
srcDir = ExtensionUtils.getPythonExtension(project).srcDir;
29+
}
2030

2131
public boolean isRun() {
2232
return run;
@@ -25,4 +35,15 @@ public boolean isRun() {
2535
public void setRun(boolean run) {
2636
this.run = run;
2737
}
38+
39+
public void setArguments(String argumentString) {
40+
arguments = argumentString.split("\\s+");
41+
}
42+
43+
public String[] getArguments() {
44+
if (arguments == null) {
45+
return new String[]{srcDir};
46+
}
47+
return arguments;
48+
}
2849
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void apply(final Project project) {
101101
*
102102
* This uses the mypy.ini file if present to configure mypy.
103103
*/
104-
MypyExtension mypy = ExtensionUtils.maybeCreate(project, "mypy", MypyExtension.class);
104+
MypyExtension mypy = ExtensionUtils.maybeCreate(project, "mypy", MypyExtension.class, project);
105105
project.getTasks().create(TASK_MYPY.getValue(), MypyTask.class,
106106
task -> task.onlyIf(it -> project.file(settings.srcDir).exists() && mypy.isRun()));
107107

pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/tasks/MypyTask.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
package com.linkedin.gradle.python.tasks;
1717

18+
import com.linkedin.gradle.python.extension.MypyExtension;
1819
import com.linkedin.gradle.python.extension.PythonDetails;
20+
import com.linkedin.gradle.python.util.ExtensionUtils;
21+
import org.gradle.api.Project;
1922
import org.gradle.process.ExecResult;
2023

2124

@@ -24,7 +27,10 @@ public class MypyTask extends AbstractPythonMainSourceDefaultTask {
2427
public void preExecution() {
2528
PythonDetails mypyDetails = getPythonDetails();
2629
args(mypyDetails.getVirtualEnvironment().findExecutable("mypy").getAbsolutePath());
27-
args(getPythonExtension().srcDir);
30+
31+
Project project = getProject();
32+
MypyExtension mypy = ExtensionUtils.maybeCreate(project, "mypy", MypyExtension.class, project);
33+
args(mypy.getArguments());
2834
}
2935

3036
public void processResults(ExecResult results) {

0 commit comments

Comments
 (0)
0