Skip to content

Commit d39e50a

Browse files
authored
Merge pull request #318 from zvezdan/fix-abi-container
Fix empty ABI container issue.
2 parents b57fe87 + 9d28b02 commit d39e50a

File tree

6 files changed

+104
-3
lines changed

6 files changed

+104
-3
lines changed

pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/ParallelWheelsIntegrationTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class ParallelWheelsIntegrationTest extends Specification {
152152

153153
then:
154154
result.task(':foo:pytest').outcome == TaskOutcome.SUCCESS //using pytest since it will always require deps
155-
result.task(':foo:parallelWheels').outcome == TaskOutcome.SUCCESS //the task isn't part of the graph
155+
def taskOutcome = result.task(':foo:parallelWheels').outcome
156+
taskOutcome == TaskOutcome.SUCCESS || taskOutcome == TaskOutcome.UP_TO_DATE
156157
}
157158
}

pygradle-plugin/src/integTest/groovy/com/linkedin/gradle/python/plugin/PythonPluginIntegrationTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PythonPluginIntegrationTest extends Specification {
6060
result.task(':foo:installPythonRequirements').outcome == TaskOutcome.SUCCESS
6161
result.task(':foo:installTestRequirements').outcome == TaskOutcome.SUCCESS
6262
result.task(':foo:createVirtualEnvironment').outcome == TaskOutcome.SUCCESS
63+
result.task(':foo:getProbedTags').outcome == TaskOutcome.SUCCESS
6364
result.task(':foo:installProject').outcome == TaskOutcome.SUCCESS
6465
result.task(':foo:pytest').outcome == TaskOutcome.SUCCESS
6566
result.task(':foo:check').outcome == TaskOutcome.SUCCESS
@@ -122,6 +123,7 @@ class PythonPluginIntegrationTest extends Specification {
122123
result.task(':foo:installPythonRequirements').outcome == TaskOutcome.SUCCESS
123124
result.task(':foo:installTestRequirements').outcome == TaskOutcome.SUCCESS
124125
result.task(':foo:createVirtualEnvironment').outcome == TaskOutcome.SUCCESS
126+
result.task(':foo:getProbedTags').outcome == TaskOutcome.SUCCESS
125127
result.task(':foo:installProject').outcome == TaskOutcome.SUCCESS
126128
result.task(':foo:pytest').outcome == TaskOutcome.SUCCESS
127129
result.task(':foo:check').outcome == TaskOutcome.SUCCESS

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.linkedin.gradle.python.plugin.internal.ValidationPlugin;
2222
import com.linkedin.gradle.python.tasks.CleanSaveVenvTask;
2323
import com.linkedin.gradle.python.tasks.GenerateSetupPyTask;
24+
import com.linkedin.gradle.python.tasks.GetProbedTagsTask;
2425
import com.linkedin.gradle.python.tasks.InstallVirtualEnvironmentTask;
2526
import com.linkedin.gradle.python.tasks.PinRequirementsTask;
2627
import com.linkedin.gradle.python.tasks.provides.ProvidesVenv;
@@ -49,6 +50,7 @@
4950
import static com.linkedin.gradle.python.util.StandardTextValues.CONFIGURATION_VENV;
5051
import static com.linkedin.gradle.python.util.StandardTextValues.CONFIGURATION_WHEEL;
5152
import static com.linkedin.gradle.python.util.StandardTextValues.TASK_CLEAN_SAVE_VENV;
53+
import static com.linkedin.gradle.python.util.StandardTextValues.TASK_GET_PROBED_TAGS;
5254
import static com.linkedin.gradle.python.util.StandardTextValues.TASK_PIN_REQUIREMENTS;
5355
import static com.linkedin.gradle.python.util.StandardTextValues.TASK_SETUP_LINKS;
5456
import static com.linkedin.gradle.python.util.StandardTextValues.TASK_SETUP_PY_WRITER;
@@ -103,12 +105,18 @@ public void apply(final Project project) {
103105
task.dependsOn(pinRequirementsTask);
104106
task.setPythonDetails(settings.getDetails());
105107
});
108+
// Ensure that ABI container is populated when virtual environment creation task is up-to-date.
109+
project.getTasks().create(TASK_GET_PROBED_TAGS.getValue(), GetProbedTagsTask.class, task -> {
110+
task.dependsOn(TASK_VENV_CREATE.getValue());
111+
task.setPythonDetails(settings.getDetails());
112+
});
106113

107114
/*
108115
* Creates a link so users can activate into the virtual environment.
109116
*/
110117
project.getTasks().create(TASK_SETUP_LINKS.getValue(), task -> {
111118
task.dependsOn(project.getTasks().getByName(TASK_VENV_CREATE.getValue()));
119+
task.dependsOn(project.getTasks().getByName(TASK_GET_PROBED_TAGS.getValue()));
112120
task.getOutputs().file(settings.getDetails().getActivateLink());
113121

114122
task.doLast(it -> {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.tasks;
17+
18+
import com.linkedin.gradle.python.extension.PythonDetails;
19+
import com.linkedin.gradle.python.tasks.action.ProbeVenvInfoAction;
20+
import com.linkedin.gradle.python.tasks.provides.ProvidesVenv;
21+
import com.linkedin.gradle.python.wheel.EditablePythonAbiContainer;
22+
import org.gradle.api.DefaultTask;
23+
import org.gradle.api.tasks.TaskAction;
24+
25+
26+
/**
27+
* Get supported wheel tags from previously probed virtual environment.
28+
*
29+
* <p>When virtual environment creation task is up-to-date,
30+
* then ABI container does not get populated, remains empty, and
31+
* no cached wheels can match any tags. This task ensures that
32+
* the container does get populated, regardless of virtual environment
33+
* creation task outcome.</p>
34+
*/
35+
public class GetProbedTagsTask extends DefaultTask implements ProvidesVenv {
36+
private PythonDetails pythonDetails;
37+
private EditablePythonAbiContainer editablePythonAbiContainer;
38+
39+
@TaskAction
40+
public void getProbedTags() {
41+
ProbeVenvInfoAction.getProbedTags(getProject(), pythonDetails, editablePythonAbiContainer);
42+
}
43+
44+
@Override
45+
public void setEditablePythonAbiContainer(EditablePythonAbiContainer editablePythonAbiContainer) {
46+
this.editablePythonAbiContainer = editablePythonAbiContainer;
47+
}
48+
49+
public PythonDetails getPythonDetails() {
50+
return pythonDetails;
51+
}
52+
53+
public void setPythonDetails(PythonDetails pythonDetails) {
54+
this.pythonDetails = pythonDetails;
55+
}
56+
}

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
import java.io.InputStream;
3434
import java.io.OutputStream;
3535

36-
class ProbeVenvInfoAction {
36+
public class ProbeVenvInfoAction {
3737

38+
private static final String PROBE_DIR_NAME = "probe-venv";
3839
private static final Logger logger = Logging.getLogger(ProbeVenvInfoAction.class);
3940

4041
private ProbeVenvInfoAction() {
@@ -50,6 +51,25 @@ static void probeVenv(Project project, PythonDetails pythonDetails,
5051
}
5152
}
5253

54+
/**
55+
* Populate the ABI container with supported wheel tags from probed environment.
56+
*
57+
* @param project current project
58+
* @param pythonDetails current python details
59+
* @param editablePythonAbiContainer the ABI container object to populate
60+
*/
61+
public static void getProbedTags(Project project,
62+
PythonDetails pythonDetails,
63+
EditablePythonAbiContainer editablePythonAbiContainer) {
64+
File probeDir = new File(project.getBuildDir(), PROBE_DIR_NAME);
65+
File supportedAbiFormatsFile = getSupportedAbiFormatsFile(probeDir, pythonDetails);
66+
try {
67+
getSavedTags(pythonDetails, editablePythonAbiContainer, supportedAbiFormatsFile);
68+
} catch (IOException e) {
69+
logger.info("Unable to probe venv for supported wheel tags. Ignoring the error. May slow the build.");
70+
}
71+
}
72+
5373
private static void doProbe(Project project, PythonDetails pythonDetails,
5474
EditablePythonAbiContainer editablePythonAbiContainer) throws IOException {
5575
InputStream wheelApiResource = ProbeVenvInfoAction.class.getClassLoader()
@@ -58,7 +78,7 @@ private static void doProbe(Project project, PythonDetails pythonDetails,
5878
byte[] buffer = new byte[wheelApiResource.available()];
5979
wheelApiResource.read(buffer);
6080

61-
File probeDir = new File(project.getBuildDir(), "probe-venv");
81+
File probeDir = new File(project.getBuildDir(), PROBE_DIR_NAME);
6282
probeDir.mkdirs();
6383

6484
OutputStream outStream = new FileOutputStream(getPythonFileForSupportedWheels(probeDir));
@@ -71,7 +91,20 @@ private static void doProbe(Project project, PythonDetails pythonDetails,
7191
execSpec.args(supportedAbiFormatsFile.getAbsolutePath());
7292
});
7393

94+
/*
95+
* The code for this function was originally here.
96+
* Still making this call to benefit AbstractPythonInfrastructureDefaultTask,
97+
* although it's not necessary for InstallVirtualEnvironmentTask because
98+
* GetProbedTagsTask will get the tags.
99+
*/
100+
getSavedTags(pythonDetails, editablePythonAbiContainer, supportedAbiFormatsFile);
101+
}
102+
103+
private static void getSavedTags(PythonDetails pythonDetails,
104+
EditablePythonAbiContainer editablePythonAbiContainer,
105+
File supportedAbiFormatsFile) throws IOException {
74106
JsonArray array = Json.parse(new FileReader(supportedAbiFormatsFile)).asArray();
107+
75108
for (JsonValue jsonValue : array) {
76109
JsonObject entry = jsonValue.asObject();
77110
String pythonTag = entry.get("pythonTag").asString();

pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/util/StandardTextValues.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public enum StandardTextValues {
4848
TASK_PYTEST("pytest"),
4949
TASK_SETUP_LINKS("installLinks"),
5050
TASK_VENV_CREATE("createVirtualEnvironment"),
51+
TASK_GET_PROBED_TAGS("getProbedTags"),
5152
TASK_PIN_REQUIREMENTS("pinRequirements"),
5253
TASK_SETUP_PY_WRITER("generateSetupPy"),
5354
DOCUMENTATION_GROUP("documentation"),

0 commit comments

Comments
 (0)