Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #49 from palantir/ngates/conda-build-version
Browse files Browse the repository at this point in the history
Pin conda build version
  • Loading branch information
gatesn authored May 11, 2017
2 parents fba0f41 + db8e8c3 commit 4e3e8f0
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author mnazbro
*/
public class AfterEvaluateAction implements Action<Project> {
public final class AfterEvaluateAction implements Action<Project> {

private final OperatingSystem os;
private final Configuration configuration;
Expand Down Expand Up @@ -64,7 +64,7 @@ public AfterEvaluateAction(
}

@Override
public final void execute(Project project) {
public void execute(Project project) {
MinicondaExtension miniconda = project.getExtensions().getByType(MinicondaExtension.class);
miniconda.validate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MinicondaExtension {
private final Project project;

private String minicondaVersion;
private String condaBuildVersion;
private int pythonVersion = DEFAULT_PYTHON_VERSION;
private File bootstrapDirectoryPrefix = DEFAULT_BOOTSTRAP_DIRECTORY_PREFIX;
private File buildEnvironmentDirectory = null;
Expand Down Expand Up @@ -161,6 +162,14 @@ public final void setMinicondaVersion(String minicondaVersion) {
this.minicondaVersion = minicondaVersion;
}

public final String getCondaBuildVersion() {
return condaBuildVersion;
}

public final void setCondaBuildVersion(String condaBuildVersion) {
this.condaBuildVersion = condaBuildVersion;
}

public final int getPythonVersion() {
return pythonVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author mnazbro
*/
public class MinicondaInstaller {
public final class MinicondaInstaller {
private static final int POTENTIAL_LEGACY_PYTHON_VERSION = 2;
private static final VersionNumber MINIMUM_NON_LEGACY_VERSION = VersionNumber.parse("3.16.0");
private static final String CONFIGURATION_NAME = "minicondaInstaller";
Expand All @@ -43,7 +43,7 @@ public MinicondaInstaller(OperatingSystem os, MinicondaExtension miniconda) {
this.miniconda = miniconda;
}

public final void addToDependencyHandler(DependencyHandler handler) {
public void addToDependencyHandler(DependencyHandler handler) {
final Map<String, String> map = new HashMap<>();
map.put("group", "miniconda");
map.put("name", getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* @author pbiswal
*/
public class MinicondaPlugin implements Plugin<Project> {
public final class MinicondaPlugin implements Plugin<Project> {
private static final Logger LOG = LoggerFactory.getLogger(MinicondaPlugin.class);

private static final OperatingSystem OS = OperatingSystem.current();
Expand All @@ -49,7 +49,7 @@ public class MinicondaPlugin implements Plugin<Project> {
private static final String IVY_REPO_URL = "https://repo.continuum.io";

@Override
public final void apply(Project project) {
public void apply(Project project) {
createIvyRepository(project);

TaskContainer tasks = project.getTasks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
* @author mnazbro
*/
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class BootstrapPython extends AbstractExecTask<BootstrapPython> {
private static final Logger LOG = LoggerFactory.getLogger(BootstrapPython.class);

Expand All @@ -53,7 +54,7 @@ public BootstrapPython() {
super(BootstrapPython.class);
}

public final void configureAfterEvaluate(
public void configureAfterEvaluate(
final MinicondaExtension miniconda, File condaInstaller, OperatingSystem os) {
Objects.requireNonNull(miniconda, "miniconda must not be null");
Objects.requireNonNull(condaInstaller, "condaInstaller must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author jakobjuelich
*/
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class CondaBuild extends AbstractExecTask<CondaBuild> {
private static final Logger LOG = LoggerFactory.getLogger(CondaBuild.class);

Expand All @@ -52,7 +53,7 @@ public CondaBuild() {
super(CondaBuild.class);
}

public final void configureAfterEvaluate(final MinicondaExtension miniconda) {
public void configureAfterEvaluate(final MinicondaExtension miniconda) {
Objects.requireNonNull(miniconda, "miniconda must not be null");

executable(miniconda.getBootstrapDirectory().toPath().resolve("bin/conda"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author jakobjuelich
*/
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class CondaBuildCheck extends AbstractExecTask<CondaBuildCheck> {
private static final Logger LOG = LoggerFactory.getLogger(CondaBuildCheck.class);

Expand All @@ -51,7 +52,7 @@ public CondaBuildCheck() {
super(CondaBuildCheck.class);
}

public final void configureAfterEvaluate(final MinicondaExtension miniconda) {
public void configureAfterEvaluate(final MinicondaExtension miniconda) {
Objects.requireNonNull(miniconda, "miniconda must not be null");

executable(miniconda.getBootstrapDirectory().toPath().resolve("bin/conda"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.palantir.python.miniconda.tasks;

import com.palantir.python.miniconda.MinicondaExtension;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -30,7 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressFBWarnings("PT_EXTENDS_CONCRETE_TYPE")
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class ConfigureRootCondaEnv extends DefaultTask {

private static final Logger LOG = LoggerFactory.getLogger(ConfigureRootCondaEnv.class);
Expand All @@ -54,12 +53,12 @@ public static ConfigureRootCondaEnv createTask(TaskContainer tasks, BootstrapPyt
}

@OutputFile
public final File getOutputFile() {
public File getOutputFile() {
return new File(miniconda.getBootstrapDirectory(), ".condarc");
}

@TaskAction
public final void createCondaRcFile() {
public void createCondaRcFile() {
LOG.info("writing a condarc file to {}", getOutputFile().getAbsolutePath());

String condaRc = "channels: []\ndefault_channels: []\n";
Expand All @@ -71,7 +70,7 @@ public final void createCondaRcFile() {
}
}

public final void configureAfterEvaluate(final MinicondaExtension minicondaExtension) {
public void configureAfterEvaluate(final MinicondaExtension minicondaExtension) {
this.miniconda = minicondaExtension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

import com.palantir.python.miniconda.MinicondaExtension;
import com.palantir.python.miniconda.MinicondaUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;
import org.gradle.api.Task;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.AbstractExecTask;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.process.ExecResult;
import org.gradle.process.internal.ExecAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,6 +38,7 @@
*
* Created by jakobjuelich on 3/7/17.
*/
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class SetupCondaBuild extends AbstractExecTask<SetupCondaBuild> {

private static final Logger LOG = LoggerFactory.getLogger(SetupCondaBuild.class);
Expand All @@ -59,26 +63,42 @@ public SetupCondaBuild() {
super(SetupCondaBuild.class);
}

public final void configureAfterEvaluate(final MinicondaExtension miniconda) {
public void configureAfterEvaluate(final MinicondaExtension miniconda) {
Objects.requireNonNull(miniconda, "miniconda must not be null");

final Path condaExec = miniconda.getBootstrapDirectory().toPath().resolve("bin/conda");
executable(condaExec);
args("install", "--quiet", "--yes", "conda-build");
args("--override-channels");
args("install", "--quiet", "--yes", "--override-channels");
args(MinicondaUtils.convertChannelsToArgs(miniconda.getChannels()));

if (miniconda.getCondaBuildVersion() != null) {
args("conda-build==" + miniconda.getCondaBuildVersion());
} else {
args("conda-build");
}

LOG.info("{} configured to execute {}", getName(), getCommandLine());

this.getOutputs().upToDateWhen(new Spec<Task>() {
getInputs().property("conda-build-version", miniconda.getCondaBuildVersion());
getOutputs().upToDateWhen(new Spec<Task>() {
@Override
public boolean isSatisfiedBy(Task task) {
ExecAction execAction = SetupCondaBuild.this.getExecActionFactory().newExecAction();
execAction.executable(condaExec);
execAction.args("build", "-V"); // will error if build is not installed, otherwise just print stuff
execAction.setIgnoreExitValue(true);
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
ExecAction execAction = SetupCondaBuild.this.getExecActionFactory().newExecAction();
execAction.executable(condaExec);
execAction.args("build", "-V"); // will error if build is not installed, otherwise just print stuff
execAction.setIgnoreExitValue(true);
execAction.setErrorOutput(os);

String expectedOutput = "conda-build " + miniconda.getCondaBuildVersion();
ExecResult result = execAction.execute();

return 0 == execAction.execute().getExitValue();
return result.getExitValue() == 0
&& (miniconda.getCondaBuildVersion() == null
|| os.toString("UTF-8").trim().equals(expectedOutput));
} catch (IOException e) {
return false;
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*
* @author mnazbro
*/
@SuppressWarnings("checkstyle:DesignForExtension") // tasks need non-final getters
public class SetupPython extends AbstractExecTask<SetupPython> {
private static final Logger LOG = LoggerFactory.getLogger(SetupPython.class);

Expand All @@ -54,7 +55,7 @@ public SetupPython() {
super(SetupPython.class);
}

public final void configureAfterEvaluate(final MinicondaExtension miniconda) {
public void configureAfterEvaluate(final MinicondaExtension miniconda) {
Objects.requireNonNull(miniconda, "miniconda must not be null");

getInputs().property("packages", miniconda.getPackages());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,28 @@ class MinicondaBuildTest extends Specification {

def 'second setupCondaBuild up to date'() {
when:
def runner = GradleRunner.create()
.forwardOutput()
.withProjectDir(tempDirectory)
.withArguments("--info", "--stacktrace", ":setupCondaBuild")
.withPluginClasspath()
BuildResult firstResult = runner.build()
def runnerForVersion = { condaBuildVersion ->
return GradleRunner.create()
.forwardOutput()
.withProjectDir(tempDirectory)
.withPluginClasspath()
.withArguments(
"--info", "--stacktrace", ":setupCondaBuild", "-PcondaBuildVersion=${condaBuildVersion}")
}

BuildResult firstResult = runnerForVersion("2.1.9").build()
LOG.info(firstResult.getOutput())

BuildResult secondResult = runner.build()
BuildResult secondResult = runnerForVersion("2.1.9").build()
LOG.info(secondResult.getOutput())

BuildResult thirdResult = runnerForVersion("2.1.8").build()
LOG.info(thirdResult.getOutput())

then:
firstResult.task(":setupCondaBuild").outcome == TaskOutcome.SUCCESS
secondResult.task(":setupCondaBuild").outcome == TaskOutcome.UP_TO_DATE
thirdResult.task(":setupCondaBuild").outcome == TaskOutcome.SUCCESS
}

}
3 changes: 2 additions & 1 deletion src/test/resources/test-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
}

miniconda {
minicondaVersion = '3.18.3'
minicondaVersion = '4.3.11'
condaBuildVersion = findProperty('condaBuildVersion')
packages = ['python']
buildOutputDirectory = project.getBuildDir().toPath().resolve("output")
}

0 comments on commit 4e3e8f0

Please sign in to comment.