Coder Social home page Coder Social logo

Comments (3)

JLLeitschuh avatar JLLeitschuh commented on May 19, 2024

I solved this problem by creating my own task and plugin in gradle that imports this plugin.

Here's the code I used to fix this problem for anyone else that needs it (both are in groovy in our buildSrc project).

You'll have to add the imports yourself.

class PythonEggDistributionPlugin extends PythonBasePlugin {
    public final static String TASK_PACKAGE_EGG_DIST = 'packageEggDist'

    @Override
    void applyTo(Project project) {

        /**
         * Create a Python source distribution.
         */
        def eggDistPackageTask = project.tasks.create(TASK_PACKAGE_EGG_DIST, SourceEggTask) {
            dependsOn(project.tasks.getByName(PythonPlugin.TASK_INSTALL_PROJECT))
        }

        def eggDistArtifactInfo = [
                name: project.name,
                type: 'egg',
                extension: 'egg',
                file: eggDistPackageTask.getEggDistOutput(),
                builtBy: project.tasks.getByName(TASK_PACKAGE_EGG_DIST),
        ]

        project.artifacts.add(PythonPlugin.CONFIGURATION_DEFAULT, eggDistArtifactInfo)
    }
}
/**
 * A task that allows us to create a python egg piggy backing on the linkedin python plugin
 */
class SourceEggTask extends DefaultTask implements FailureReasonProvider {

    private final TeeOutputContainer container = new TeeOutputContainer();

    @TaskAction
    public void packageEggDist() {
        // Fixes a groovy scoping problem
        final TeeOutputContainer containerAlias = container

        final PythonExtension settings = getProject().getExtensions().getByType(PythonExtension.class);

        getProject().exec(new Action<ExecSpec>() {
            @Override
            public void execute(ExecSpec execSpec) {
                containerAlias.setOutputs(execSpec);
                execSpec.environment(settings.pythonEnvironmentDistgradle);
                execSpec.commandLine(
                        VirtualEnvExecutableHelper.getPythonInterpreter(settings.getDetails()),
                        "setup.py",
                        "bdist_egg",
                        "--dist-dir",
                        getDistDir().getAbsolutePath());
            }
        });
    }

    @OutputFile
    public File getEggDistOutput() {
        Project project = getProject();
        return new File(getDistDir(),
                String.format(
                        "%s-%s-py2.7.egg",
                        project.getName(),
                        /*
                         * For some reason the build spits out a file with
                         *  the `-` character replaced by the `_` character.
                         */
                        project.getVersion().toString().replace("-", "_")));
    }

    private File getDistDir() {
        return new File(getProject().getBuildDir(), "distributions");
    }

    @Override
    public String getReason() {
        return container.getCommandOutput();
    }
}

from pygradle.

JLLeitschuh avatar JLLeitschuh commented on May 19, 2024

Note: I originally had the getEggDistOutput method wrong. I have since fixed it as you can see above.

from pygradle.

JLLeitschuh avatar JLLeitschuh commented on May 19, 2024

Updated version for newest release of plugin:

class SourceEggTask extends AbstractPythonMainSourceDefaultTask {

    public SourceEggTask() {
        args("setup.py",
                "bdist_egg",
                "--dist-dir",
                getDistDir().getAbsolutePath())
    }

    @Override
    public void processResults(ExecResult execResult) {
    }

    @OutputFile
    public File getEggDistOutput() {
        Project project = getProject();
        return new File(getDistDir(),
                String.format(
                        "%s-%s-py2.7.egg",
                        project.getName(),
                        /*
                         * For some reason the build spits out a file with
                         *  the `-` character replaced by the `_` character.
                         */
                        project.getVersion().toString().replace("-", "_")));
    }


    private File getDistDir() {
        return new File(getProject().getBuildDir(), "distributions");
    }
}

from pygradle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.