Skip to content

Commit

Permalink
Merge pull request #291 from zvezdan/revert-cli-refactoring
Browse files Browse the repository at this point in the history
Revert cli refactoring
  • Loading branch information
zvezdan authored Apr 13, 2019
2 parents 4c3f4d9 + 52fe91c commit 905d8fd
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 478 deletions.
10 changes: 5 additions & 5 deletions docs/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ test and add `mavenLocal()` to the repositories. This will configure your
project to look in `~/.m2` in addition to other repositories you have
configured when pulling artifacts.

If you are building on Windows, PyGradle will avoid using your system temporary
folder for integration tests and instead create and use the folder `c:\tmp`. This
is to avoid issues with Windows's 260 character path limit. Make sure your user
If you are building on Windows, PyGradle will avoid using your system temporary
folder for integration tests and instead create and use the folder `c:\tmp`. This
is to avoid issues with Windows's 260 character path limit. Make sure your user
account has the ablity to create and use this folder or your integration tests will fail.

If you are using Windows 10, it is possible to go beyond that 260 character limit,
but not with this product. That policy change only applies to managed applications.
If you are using Windows 10, it is possible to go beyond that 260 character limit,
but not with this product. That policy change only applies to managed applications.
PyGradle's unit tests are not managed applications.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ParallelWheelsIntegrationTest extends Specification {
result.task(':foo:pytest').outcome == TaskOutcome.SUCCESS
result.task(':foo:check').outcome == TaskOutcome.SUCCESS
result.task(':foo:build').outcome == TaskOutcome.SUCCESS
result.task(':foo:assembleContainers').outcome == TaskOutcome.SUCCESS
result.task(':foo:buildPex').outcome == TaskOutcome.SUCCESS

deployablePath.resolve('hello_world').toFile().exists()
deployablePath.resolve(PexFileUtil.createThinPexFilename('foo')).toFile().exists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class PexIntegrationTest extends Specification {
result.task(':foo:check').outcome == TaskOutcome.SUCCESS
result.task(':foo:build').outcome == TaskOutcome.SUCCESS
result.task(':foo:buildPex').outcome == TaskOutcome.SUCCESS
result.task(':foo:assembleContainers').outcome == TaskOutcome.SUCCESS

deployablePath.resolve('hello_world').toFile().exists()
deployablePath.resolve(PexFileUtil.createThinPexFilename('foo')).toFile().exists()
Expand Down Expand Up @@ -130,7 +129,6 @@ class PexIntegrationTest extends Specification {
result.task(':foo:check').outcome == TaskOutcome.SUCCESS
result.task(':foo:build').outcome == TaskOutcome.SUCCESS
result.task(':foo:buildPex').outcome == TaskOutcome.SUCCESS
result.task(':foo:assembleContainers').outcome == TaskOutcome.SUCCESS

Path deployablePath = testProjectDir.root.toPath().resolve(Paths.get('foo', 'build', 'deployable', "bin"))
def pexFile = deployablePath.resolve(PexFileUtil.createFatPexFilename('hello_world'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package com.linkedin.gradle.python

import com.linkedin.gradle.python.extension.PexExtension
import com.linkedin.gradle.python.extension.PythonDetails
import com.linkedin.gradle.python.extension.PythonDetailsFactory
import com.linkedin.gradle.python.util.ApplicationContainer
import org.gradle.api.GradleException
import org.gradle.api.Project

Expand Down Expand Up @@ -82,28 +80,6 @@ class PythonExtension {
/* Container of the details related to the venv/python instance */
private final PythonDetails details

/*
* "Application container" defines the format for bundling the application
* into a single file distribution. Examples include pex, shiv, and xar.
* Not all plugins using this extension support such containers, but for
* u/i purposes, it's convenient to add this here. This allows the
* following in a build.gradle file:
*
* python {
* container = "shiv"
* }
*
* These will simply be ignored in extension clients that don't need it.
*
* Downstream consumers can extend the map between container short names
* appropriate for the build.gradle UI, and the container class
* this maps to. They can also set the default container, which allows
* them e.g. to choose shivs over pexes.
*/
public Map<String, ApplicationContainer> containers
String container
ApplicationContainer defaultContainer

PythonExtension(Project project) {
this.details = PythonDetailsFactory.makePythonDetails(project, null)
docsDir = Paths.get(project.projectDir.absolutePath, "docs").toFile().path
Expand All @@ -116,18 +92,10 @@ class PythonExtension {
def applicationDirectory = PythonDetailsFactory.getPythonApplicationDirectory()

pythonEnvironment = [
'PATH': "${ -> details.virtualEnv.toPath().resolve(applicationDirectory).toAbsolutePath().toString() }"
+ File.pathSeparator
+ System.getenv('PATH'),
]
'PATH': "${ -> details.virtualEnv.toPath().resolve(applicationDirectory).toAbsolutePath().toString() }" + File.pathSeparator + System.getenv('PATH'),]

pythonEnvironmentDistgradle = [
'PYGRADLE_PROJECT_NAME' : project.name,
'PYGRADLE_PROJECT_VERSION': "${ -> project.version }",
]

defaultContainer = new PexExtension(project)
containers = [pex: defaultContainer]
pythonEnvironmentDistgradle = ['PYGRADLE_PROJECT_NAME' : project.name,
'PYGRADLE_PROJECT_VERSION': "${ -> project.version }",]

/*
* NOTE: Do lots of sanity checking and validation here.
Expand Down Expand Up @@ -187,15 +155,4 @@ class PythonExtension {
void setPinnedFile(File pinnedFile) {
this.pinnedFile = pinnedFile
}

/*
* Use this as the programmatic API for getting the current container extension.
*/
ApplicationContainer getApplicationContainer() {
// Why am I doing it this way? Because if the container isn't set
// (i.e. it is null) I want to return the default container. But if
// it's set to a bogus value, I want it to return the null so the
// caller will know they have a bogus value.
return container == null ? defaultContainer : containers.get(container)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@
*/
package com.linkedin.gradle.python.extension;

import com.linkedin.gradle.python.PythonExtension;
import com.linkedin.gradle.python.tasks.BuildPexTask;
import com.linkedin.gradle.python.util.ApplicationContainer;
import com.linkedin.gradle.python.util.ExtensionUtils;
import com.linkedin.gradle.python.util.OperatingSystem;
import com.linkedin.gradle.python.util.StandardTextValues;
import org.gradle.api.Project;

import java.io.File;


public class PexExtension implements ApplicationContainer {
// 2019-04-01(warsaw): For backward compatibility, we must expose a no-op
// buildPex task unconditionally. This will be created in
// PythonContainerPlugin and tied into the task hierarchy in the right
// place. realBuildPex task is the actual pex building task, but these
// are only needed if pexes are selected (and won't get created until
// after build.gradle evaluation).
//
// Yes, this is gross and we should deprecate this mess at our earliest convenience.
public static final String TASK_BUILD_PEX = "realBuildPex";
public static final String TASK_BUILD_NOOP_PEX = "buildPex";

public class PexExtension implements ZipappExtension {
private File cache;
// Default to fat zipapps on Windows, since our wrappers are fairly POSIX specific.
private boolean isFat = OperatingSystem.current().isWindows();
Expand Down Expand Up @@ -109,19 +93,4 @@ public File getCache() {
public void setCache(File cache) {
this.cache = cache;
}

public void addExtensions(Project project) {
ExtensionUtils.maybeCreatePexExtension(project);
}

public void addDependencies(Project project) {
final PythonExtension extension = ExtensionUtils.getPythonExtension(project);

project.getDependencies().add(StandardTextValues.CONFIGURATION_BUILD_REQS.getValue(),
extension.forcedVersions.get("pex"));
}

public void makeTasks(Project project) {
project.getTasks().create(TASK_BUILD_PEX, BuildPexTask.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.linkedin.gradle.python.util;
package com.linkedin.gradle.python.extension;

public interface ZipappContainer extends ApplicationContainer {

public interface ZipappExtension {
/**
* @return when <code>true</code>, then skinny pex's will be used.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,25 @@
*/
package com.linkedin.gradle.python.plugin;

import com.linkedin.gradle.python.util.ApplicationContainer;
import com.linkedin.gradle.python.tasks.GenerateCompletionsTask;
import com.linkedin.gradle.python.util.ExtensionUtils;
import com.linkedin.gradle.python.util.StandardTextValues;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskContainer;


public class PythonCliDistributionPlugin extends PythonContainerPlugin {
public class PythonCliDistributionPlugin extends PythonBasePlugin {

public static final String TASK_GENERATE_COMPLETIONS = "generateCompletions";

@Override
public void applyTo(Project project) {
project.getPlugins().apply(PythonContainerPlugin.class);
project.getPlugins().apply(PythonPexDistributionPlugin.class);
ExtensionUtils.maybeCreateCliExtension(project);

TaskContainer tasks = project.getTasks();
GenerateCompletionsTask completionsTask = project.getTasks().create(TASK_GENERATE_COMPLETIONS, GenerateCompletionsTask.class);
completionsTask.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue()));

GenerateCompletionsTask completionsTask = tasks.create(TASK_GENERATE_COMPLETIONS, GenerateCompletionsTask.class);
completionsTask.dependsOn(tasks.getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue()));

tasks.getByName(ApplicationContainer.TASK_ASSEMBLE_CONTAINERS)
.dependsOn(project.getTasks().getByName(TASK_GENERATE_COMPLETIONS));
project.getTasks().getByName(PythonPexDistributionPlugin.TASK_BUILD_PEX).dependsOn(project.getTasks().getByName(TASK_GENERATE_COMPLETIONS));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.linkedin.gradle.python.plugin;

import com.linkedin.gradle.python.util.ApplicationContainer;
import com.linkedin.gradle.python.extension.DeployableExtension;
import com.linkedin.gradle.python.util.ExtensionUtils;
import com.linkedin.gradle.python.util.FileSystemUtils;
Expand Down Expand Up @@ -103,9 +102,8 @@ public void apply(final Project project) {
copy.from(resourceConf);
copy.into(deployableExtension.getDeployableBuildDir().toPath().resolve("resource"));
});

// Make sure we've copied all the files before running the task: packageDeployable
project.getTasks().getByName(ApplicationContainer.TASK_PACKAGE_DEPLOYABLE)
project.getTasks().getByName(PythonPexDistributionPlugin.TASK_PACKAGE_DEPLOYABLE)
.dependsOn(project.getTasks().getByName(TASK_PACKAGE_RESOURCE_FILES));
}
}
Loading

0 comments on commit 905d8fd

Please sign in to comment.