Skip to content

Commit

Permalink
Merge pull request #199 from ethankhall/master
Browse files Browse the repository at this point in the history
Added SupportsPackageInfoSettings
  • Loading branch information
Ethan Hall authored Mar 14, 2018
2 parents 7d56f40 + 57183b0 commit 4203ba0
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 153 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.build.version;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Properties;

class VersionFile {
private static final String VERSION = "version";

static Version getVersion(File propertyFile) {
try {
Properties properties = new Properties();
properties.load(new FileReader(propertyFile));
return new Version(properties.getProperty(VERSION));
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ public class VersionPlugin implements Plugin<Project> {

@Override
public void apply(Project target) {
if(target.getRootProject() != target) {
if (target.getRootProject() != target) {
throw new GradleException("Cannot apply dependency plugin to a non-root project");
}

File versionProperties = target.file("version.properties");

Version version = VersionFile.getVersion(versionProperties);

if(!target.hasProperty("release") || !Boolean.parseBoolean((String) target.property("release"))) {
version = version.withNextPatch().asSnapshot();
if (!target.hasProperty("release") || !Boolean.parseBoolean((String) target.property("release"))) {
version = version.asSnapshot();
}

logger.lifecycle("Building using version {}", version);
target.allprojects(new VersionAction(version));

VersionBumpTask versionBump = target.getTasks().create("versionBump", VersionBumpTask.class);
versionBump.setVersionFile(versionProperties);
versionBump.setCurrentVersion(version);
}

private static class VersionAction implements Action<Project> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ package com.linkedin.gradle.python.plugin.testutils

trait ProjectLayoutRule {
abstract void before() throws Throwable

abstract void after()

abstract void create() throws IOException

abstract File newFile(String fileName) throws IOException

abstract File newFile() throws IOException

abstract File newFolder(String folder) throws IOException

abstract File newFolder(String... folderNames) throws IOException

abstract File newFolder() throws IOException

abstract File getRoot()

abstract void delete()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.linkedin.gradle.python.tasks.GenerateSetupPyTask;
import com.linkedin.gradle.python.tasks.InstallVirtualEnvironmentTask;
import com.linkedin.gradle.python.tasks.PinRequirementsTask;
import com.linkedin.gradle.python.tasks.supports.SupportsPackageInfoSettings;
import com.linkedin.gradle.python.util.DefaultPackageSettings;
import com.linkedin.gradle.python.util.FileSystemUtils;
import com.linkedin.gradle.python.util.internal.PyPiRepoUtil;
import org.gradle.api.Plugin;
Expand Down Expand Up @@ -58,6 +60,9 @@ public void apply(final Project project) {
createConfigurations(project);
configureVendedDependencies(project, settings);

DefaultPackageSettings packageSettings = new DefaultPackageSettings(project.getName());
project.getTasks().withType(SupportsPackageInfoSettings.class, it -> it.setPackageSettings(packageSettings));

/*
* To prevent base dependencies, such as setuptools, from installing/reinstalling, we will
* pin their versions to values in the extension.forcedVersions map, which will contain known
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.linkedin.gradle.python.util.ExtensionUtils;
import com.linkedin.gradle.python.wheel.FileBackedWheelCache;
import com.linkedin.gradle.python.wheel.SupportedWheelFormats;
import com.linkedin.gradle.python.wheel.SupportsWheelCache;
import com.linkedin.gradle.python.tasks.supports.SupportsWheelCache;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ConfigurationContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import com.linkedin.gradle.python.PythonExtension
import com.linkedin.gradle.python.extension.PythonDetails
import com.linkedin.gradle.python.extension.WheelExtension
import com.linkedin.gradle.python.plugin.PythonHelpers
import com.linkedin.gradle.python.tasks.supports.SupportsPackageInfoSettings
import com.linkedin.gradle.python.tasks.supports.SupportsWheelCache
import com.linkedin.gradle.python.util.DefaultEnvironmentMerger
import com.linkedin.gradle.python.util.DefaultPackageSettings
import com.linkedin.gradle.python.util.DependencyOrder
import com.linkedin.gradle.python.util.EnvironmentMerger
import com.linkedin.gradle.python.util.ExtensionUtils
import com.linkedin.gradle.python.util.PackageInfo
import com.linkedin.gradle.python.util.PackageSettings
import com.linkedin.gradle.python.util.internal.TaskTimer
import com.linkedin.gradle.python.wheel.EmptyWheelCache
import com.linkedin.gradle.python.wheel.SupportsWheelCache
import com.linkedin.gradle.python.wheel.WheelCache
import org.apache.commons.io.FileUtils
import org.gradle.api.DefaultTask
Expand All @@ -47,8 +47,7 @@ import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.process.ExecResult
import org.gradle.process.ExecSpec


class BuildWheelsTask extends DefaultTask implements SupportsWheelCache {
class BuildWheelsTask extends DefaultTask implements SupportsWheelCache, SupportsPackageInfoSettings {

private static final Logger LOGGER = Logging.getLogger(BuildWheelsTask)

Expand All @@ -65,7 +64,7 @@ class BuildWheelsTask extends DefaultTask implements SupportsWheelCache {
@Optional
Map<String, String> environment

PackageSettings<PackageInfo> packageSettings = new DefaultPackageSettings(project.name)
PackageSettings<PackageInfo> packageSettings

EnvironmentMerger environmentMerger = new DefaultEnvironmentMerger()

Expand Down Expand Up @@ -147,7 +146,7 @@ class BuildWheelsTask extends DefaultTask implements SupportsWheelCache {
def numberOfInstallables = installables.size()
installables.each { File installable ->
def pyVersion = pythonDetails.getPythonVersion().pythonMajorMinor
def packageInfo = PackageInfo.fromPath(installable.path)
def packageInfo = PackageInfo.fromPath(installable)
def shortHand = packageInfo.version ? "${ packageInfo.name }-${ packageInfo.version }" : packageInfo.name

def clock = taskTimer.start(shortHand)
Expand All @@ -168,7 +167,7 @@ class BuildWheelsTask extends DefaultTask implements SupportsWheelCache {
def supportedVersions = packageSettings.getSupportedLanguageVersions(packageInfo)
if (supportedVersions != null && !supportedVersions.empty && !supportedVersions.contains(pyVersion)) {
throw new GradleException(
"Package ${packageInfo.name} works only with Python versions: ${supportedVersions}")
"Package ${ packageInfo.name } works only with Python versions: ${ supportedVersions }")
}

/*
Expand All @@ -189,7 +188,7 @@ class BuildWheelsTask extends DefaultTask implements SupportsWheelCache {

def tree = project.fileTree(
dir: wheelExtension.wheelCache,
include: "**/${packageInfo.name.replace('-', '_')}-${(packageInfo.version ?: 'unspecified').replace('-', '_')}-*.whl")
include: "**/${ packageInfo.name.replace('-', '_') }-${ (packageInfo.version ?: 'unspecified').replace('-', '_') }-*.whl")

if (tree.files.size() >= 1) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.linkedin.gradle.python.PythonExtension;
import com.linkedin.gradle.python.extension.PythonDetails;
import com.linkedin.gradle.python.plugin.PythonHelpers;
import com.linkedin.gradle.python.tasks.supports.SupportsPackageInfoSettings;
import com.linkedin.gradle.python.util.PackageInfo;
import com.linkedin.gradle.python.util.PackageSettings;
import com.linkedin.gradle.python.util.internal.TaskTimer;
import com.linkedin.gradle.python.wheel.WheelCache;
import org.apache.commons.io.FileUtils;
Expand All @@ -43,7 +45,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class ParallelWheelGenerationTask extends DefaultTask {
public class ParallelWheelGenerationTask extends DefaultTask implements SupportsPackageInfoSettings {

private static final Logger logger = Logging.getLogger(ParallelWheelGenerationTask.class);

Expand All @@ -55,6 +57,8 @@ public class ParallelWheelGenerationTask extends DefaultTask {
private PythonExtension extension;
private AtomicInteger counter = new AtomicInteger();

private PackageSettings<PackageInfo> packageSettings;

@TaskAction
public void buildWheels() {

Expand All @@ -69,9 +73,11 @@ public void buildWheels() {
Set<File> files = getFilesToConvert().getFiles();
int totalSize = files.size();
files.parallelStream().forEach(file -> {
PackageInfo packageInfo = PackageInfo.fromPath(file.getPath());
PackageInfo packageInfo = PackageInfo.fromPath(file);
TaskTimer.TickingClock clock = taskTimer.start(packageInfo.getName() + "-" + packageInfo.getVersion());
makeWheelFromSdist(progressLogger, totalSize, file);
if (!packageSettings.requiresSourceBuild(packageInfo)) {
makeWheelFromSdist(progressLogger, totalSize, file);
}
clock.stop();
});

Expand All @@ -89,7 +95,7 @@ private void makeWheelFromSdist(ProgressLogger progressLogger, int totalSize, Fi
return;
}

PackageInfo packageInfo = PackageInfo.fromPath(input.getPath());
PackageInfo packageInfo = PackageInfo.fromPath(input);
progressLogger.progress(String.format("Building wheel %s %d of %d", packageInfo.getName(), counter.incrementAndGet(), totalSize));
Optional<File> cachedWheel = wheelCache.findWheel(
packageInfo.getName(),
Expand Down Expand Up @@ -176,4 +182,14 @@ public WheelCache getWheelCache() {
public void setWheelCache(WheelCache wheelCache) {
this.wheelCache = wheelCache;
}

@Override
public void setPackageSettings(PackageSettings<PackageInfo> settings) {
this.packageSettings = settings;
}

@Override
public PackageSettings<PackageInfo> getPackageSettings() {
return this.packageSettings;
}
}
Loading

0 comments on commit 4203ba0

Please sign in to comment.