Skip to content

Commit a2689a6

Browse files
committed
Upgrade to virtualenv-16.1.0.
Provide the handling of relocated/renamed scripts in the virtualenv 16.1.0 and higher version (preparing for other changes). Handle the changed behavior of rebuild script.
1 parent b2e375b commit a2689a6

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

pivy-importer/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ task importRequiredDependencies(type: JavaExec) { task ->
6565
'setuptools-git:1.2',
6666
'six:1.11.0',
6767
'Sphinx:1.8.1',
68-
'virtualenv:16.0.0',
68+
'virtualenv:16.1.0',
6969
'wheel:0.31.1',
7070
].join(" ")
7171
def forceDeps = [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class PythonExtension {
7575
'setuptools-git': ['group': 'pypi', 'name': 'setuptools-git', 'version': '1.2'],
7676
'six' : ['group': 'pypi', 'name': 'six', 'version': '1.11.0'],
7777
'Sphinx' : ['group': 'pypi', 'name': 'Sphinx', 'version': '1.8.1'],
78-
'virtualenv' : ['group': 'pypi', 'name': 'virtualenv', 'version': '16.0.0'],
78+
'virtualenv' : ['group': 'pypi', 'name': 'virtualenv', 'version': '16.1.0'],
7979
'wheel' : ['group': 'pypi', 'name': 'wheel', 'version': '0.31.1'],
8080
]
8181

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,19 @@ public void buildVenv(@Nullable Consumer<File> customize) {
7373
customize.accept(packageDir);
7474
}
7575

76+
// In virtualenv-16.1.0 the install script was relocated and will be in 17+.
77+
Path installScriptPath = Paths.get(packageDir.toString(), "virtualenv.py");
78+
if (!Files.exists(installScriptPath)) {
79+
installScriptPath = Paths.get(packageDir.toString(), "src", "virtualenv.py");
80+
}
81+
82+
final File installScript = installScriptPath.toFile();
7683
OutputStream outputStream = new ByteArrayOutputStream();
7784
ExecResult execResult = project.exec(execSpec -> {
7885
container.setOutputs(execSpec);
79-
// For virtualenv >= 16.1, use and invoke via `-m virtualenv` below.
80-
// execSpec.environment("PYTHONPATH", new File(packageDir, "src"));
8186
execSpec.commandLine(
8287
pythonDetails.getSystemPythonInterpreter(),
83-
new File(packageDir, "virtualenv.py"),
88+
installScript,
8489
"--never-download",
8590
"--python", pythonDetails.getSystemPythonInterpreter(),
8691
"--prompt", pythonDetails.getVirtualEnvPrompt(),

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.linkedin.gradle.python.tasks.exec.ExternalExec;
2020
import org.gradle.api.logging.Logger;
2121
import org.gradle.api.logging.Logging;
22+
import org.gradle.process.ExecResult;
2223

2324
import java.io.ByteArrayOutputStream;
2425
import java.io.File;
@@ -31,7 +32,8 @@
3132
import java.util.function.Consumer;
3233

3334
public class VirtualEnvCustomizer implements Consumer<File> {
34-
35+
private static final int NO_CHANGE = 0;
36+
private static final int CHANGED = 1;
3537
private static final Logger log = Logging.getLogger(VirtualEnvCustomizer.class);
3638

3739
private final String distutilsCfg;
@@ -57,12 +59,30 @@ public void accept(File file) {
5759
throw new UncheckedIOException(e);
5860
}
5961

62+
// Since virtualenv-16.2.0 the rebuild script was renamed and relocated.
63+
Path rebuildScriptPath = path.resolve(Paths.get("bin", "rebuild-script.py"));
64+
if (!Files.exists(rebuildScriptPath)) {
65+
rebuildScriptPath = path.resolve(Paths.get("tasks", "update_embedded.py"));
66+
}
67+
6068
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
61-
exec.exec(execSpec -> {
62-
execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), path.resolve(Paths.get("bin", "rebuild-script.py")).toFile());
69+
final File rebuildScript = rebuildScriptPath.toFile();
70+
ExecResult execResult = exec.exec(execSpec -> {
71+
execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), rebuildScript);
6372
execSpec.setStandardOutput(stream);
6473
execSpec.setErrorOutput(stream);
74+
execSpec.setIgnoreExitValue(true);
6575
});
76+
77+
/*
78+
* Starting with virtualenv-16.1.0 the rebuild script returns 1 when there's a change.
79+
* Since the change is exactly what we want, we cannot allow the failure for exit code 1.
80+
*/
81+
if (execResult.getExitValue() != NO_CHANGE && execResult.getExitValue() != CHANGED) {
82+
log.lifecycle(stream.toString());
83+
execResult.assertNormalExitValue();
84+
}
85+
6686
log.info("Customized distutils.cfg");
6787
}
6888
}

0 commit comments

Comments
 (0)