-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from lorencarvalho/isort-black-tasks-take-2
Add an 'isort' & 'black' task. (take two)
- Loading branch information
Showing
8 changed files
with
206 additions
and
19 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/extension/BlackExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.linkedin.gradle.python.extension; | ||
|
||
import com.linkedin.gradle.python.extension.internal.DefaultExternalTool; | ||
|
||
|
||
public class BlackExtension extends DefaultExternalTool { | ||
} |
22 changes: 22 additions & 0 deletions
22
pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/extension/IsortExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.linkedin.gradle.python.extension; | ||
|
||
import com.linkedin.gradle.python.extension.internal.DefaultExternalTool; | ||
|
||
|
||
public class IsortExtension extends DefaultExternalTool { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...in/src/main/groovy/com/linkedin/gradle/python/extension/internal/DefaultExternalTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.linkedin.gradle.python.extension.internal; | ||
|
||
|
||
public class DefaultExternalTool { | ||
private boolean run; | ||
private String[] arguments = null; | ||
|
||
public boolean isRun() { | ||
return run; | ||
} | ||
|
||
public void setRun(boolean run) { | ||
this.run = run; | ||
} | ||
|
||
public void setArguments(String argumentString) { | ||
arguments = argumentString.split("\\s+"); | ||
} | ||
|
||
public String[] getArguments() { | ||
return arguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/tasks/BlackTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.linkedin.gradle.python.tasks; | ||
|
||
import com.linkedin.gradle.python.extension.BlackExtension; | ||
import com.linkedin.gradle.python.extension.PythonDetails; | ||
import com.linkedin.gradle.python.util.ExtensionUtils; | ||
import org.gradle.api.Project; | ||
import org.gradle.process.ExecResult; | ||
|
||
|
||
public class BlackTask extends AbstractPythonMainSourceDefaultTask { | ||
|
||
public void preExecution() { | ||
PythonDetails blackDetails = getPythonDetails(); | ||
args(blackDetails.getVirtualEnvironment().findExecutable("black").getAbsolutePath()); | ||
|
||
Project project = getProject(); | ||
BlackExtension black = ExtensionUtils.getPythonComponentExtension(project, BlackExtension.class); | ||
|
||
String[] arguments = black.getArguments(); | ||
|
||
if (arguments == null) { | ||
// Default to longer line length (160) than the default (88) | ||
// Default to check only | ||
arguments = new String[] {"--check", "-l", "160", getPythonExtension().srcDir, getPythonExtension().testDir}; | ||
} | ||
args(arguments); | ||
} | ||
|
||
public void processResults(ExecResult results) { | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/tasks/IsortTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.linkedin.gradle.python.tasks; | ||
|
||
import com.linkedin.gradle.python.extension.IsortExtension; | ||
import com.linkedin.gradle.python.extension.PythonDetails; | ||
import com.linkedin.gradle.python.util.ExtensionUtils; | ||
import org.gradle.api.Project; | ||
import org.gradle.process.ExecResult; | ||
|
||
|
||
public class IsortTask extends AbstractPythonMainSourceDefaultTask { | ||
|
||
public void preExecution() { | ||
PythonDetails isortDetails = getPythonDetails(); | ||
args(isortDetails.getVirtualEnvironment().findExecutable("isort").getAbsolutePath()); | ||
|
||
Project project = getProject(); | ||
IsortExtension isort = ExtensionUtils.getPythonComponentExtension(project, IsortExtension.class); | ||
|
||
String[] arguments = isort.getArguments(); | ||
|
||
if (arguments == null) { | ||
// Default to --check-only --recursive src/ test/ | ||
arguments = new String[]{"--check-only", "--recursive", getPythonExtension().srcDir, getPythonExtension().testDir}; | ||
} | ||
args(arguments); | ||
} | ||
|
||
public void processResults(ExecResult results) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters