From 642b36ebb4eea79199ceb7eee581de22ded4a013 Mon Sep 17 00:00:00 2001 From: Ethan Hall Date: Thu, 22 Mar 2018 11:31:05 -0700 Subject: [PATCH] Re-adding PythonWheelsDistributionPlugin Per #204, users were using this task, so we should re-add it. Creating a public name(com.linkedin.python-wheel-dist), and adding it to the tests. --- pygradle-plugin/build.gradle | 5 ++ .../plugin/PythonPluginIntegrationTest.groovy | 1 + .../plugin/PythonWheelDistributionPlugin.java | 58 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/plugin/PythonWheelDistributionPlugin.java diff --git a/pygradle-plugin/build.gradle b/pygradle-plugin/build.gradle index 454019a8..c847274b 100644 --- a/pygradle-plugin/build.gradle +++ b/pygradle-plugin/build.gradle @@ -96,6 +96,11 @@ gradlePlugin { implementationClass = 'com.linkedin.gradle.python.plugin.PythonSourceDistributionPlugin' } + pythonWheelPlugins { + id = 'com.linkedin.python-wheel-dist' + implementationClass = 'com.linkedin.gradle.python.plugin.PythonWheelDistributionPlugin' + } + pythonWebappPlugins { id = 'com.linkedin.python-web-app' implementationClass = 'com.linkedin.gradle.python.plugin.PythonWebApplicationPlugin' diff --git a/pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/PythonPluginIntegrationTest.groovy b/pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/PythonPluginIntegrationTest.groovy index bffdb34d..477cce0f 100644 --- a/pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/PythonPluginIntegrationTest.groovy +++ b/pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/PythonPluginIntegrationTest.groovy @@ -32,6 +32,7 @@ class PythonPluginIntegrationTest extends Specification { testProjectDir.buildFile << """ |plugins { | id 'com.linkedin.python' + | id 'com.linkedin.python-wheel-dist' |} | |${PyGradleTestBuilder.createRepoClosure()} diff --git a/pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/plugin/PythonWheelDistributionPlugin.java b/pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/plugin/PythonWheelDistributionPlugin.java new file mode 100644 index 00000000..ab6f9d18 --- /dev/null +++ b/pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/plugin/PythonWheelDistributionPlugin.java @@ -0,0 +1,58 @@ +/* + * 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.plugin; + +import com.linkedin.gradle.python.util.StandardTextValues; +import org.gradle.api.Project; + +import java.io.File; +import java.util.LinkedHashMap; + +public class PythonWheelDistributionPlugin extends PythonBasePlugin { + @Override + public void applyTo(final Project project) { + // XXX: This needs to be adjusted to work with a build matrix one day. Until + // that is ready, we always assume pure Python 2.6 on Linux. + String version = project.getVersion().toString().replace("-", "_"); + String name = project.getName().replace("-", "_"); + final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); + + /* + * Create a Python wheel distribution. + */ + project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { + task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); + task.getOutputs().file(wheelArtifact); + task.doLast(it -> project.exec(execSpec -> { + execSpec.environment(settings.pythonEnvironmentDistgradle); + execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); + })); + }); + + LinkedHashMap wheelArtifactInfo = new LinkedHashMap<>(5); + wheelArtifactInfo.put("name", name); + wheelArtifactInfo.put("classifier", "py2-none-any"); + wheelArtifactInfo.put("type", "whl"); + wheelArtifactInfo.put("file", wheelArtifact); + wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); + + if (!version.contains("SNAPSHOT")) { + project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); + } + } + + public static final String TASK_PACKAGE_WHEEL = "packageWheel"; +}