pygradle icon indicating copy to clipboard operation
pygradle copied to clipboard

Issue with creating a virtualenv.

Open rohit-karthik opened this issue 5 years ago • 3 comments

Hello,

I tried to get pygradle working with my project, but couldn't get it to work, as during the build in the "wheel-api.py" file, I get three question marks instead of a ')': image

The error in the console: image

My build.gradle: image

I'm using VS Code as my editor on Mac OS 11.0.1. Any help would be appreciated. Thanks!

rohit-karthik avatar Jan 11 '21 01:01 rohit-karthik

I have the same problem on Ubuntu 20.04, looks like this code does not completely write file:

        InputStream wheelApiResource = ProbeVenvInfoAction.class.getClassLoader()
            .getResourceAsStream("templates/wheel-api.py");

        byte[] buffer = new byte[wheelApiResource.available()];
        wheelApiResource.read(buffer);

        File probeDir = new File(project.getBuildDir(), PROBE_DIR_NAME);
        probeDir.mkdirs();

        OutputStream outStream = new FileOutputStream(getPythonFileForSupportedWheels(probeDir));
        outStream.write(buffer);

realill avatar Feb 08 '21 23:02 realill

Ok, I think I found two solutions to this problem: First is to use JDK8, problem does not occur there.

Another one patching ./pygradle-plugin/src/main/groovy/com/linkedin/gradle/python/tasks/action/ProbeVenvInfoAction.java with following code:

    private static void doProbe(Project project, PythonDetails pythonDetails,
                          EditablePythonAbiContainer editablePythonAbiContainer) throws IOException {
        
        File probeDir = new File(project.getBuildDir(), PROBE_DIR_NAME);
        probeDir.mkdirs();

        byte[] buffer = new byte[1024];
        try(InputStream wheelApiResource = ProbeVenvInfoAction.class.getClassLoader()
            .getResourceAsStream("templates/wheel-api.py");
            OutputStream outStream = new FileOutputStream(getPythonFileForSupportedWheels(probeDir))) {
          int size;
          while((size = wheelApiResource.read(buffer)) > 0) {
            outStream.write(buffer, 0, size);
          }
       }

        File supportedAbiFormatsFile = getSupportedAbiFormatsFile(probeDir, pythonDetails);
        project.exec(execSpec -> {
            execSpec.commandLine(pythonDetails.getVirtualEnvInterpreter());
            execSpec.args(getPythonFileForSupportedWheels(probeDir));
            execSpec.args(supportedAbiFormatsFile.getAbsolutePath());
        });

        /*
         * The code for this function was originally here.
         * Still making this call to benefit AbstractPythonInfrastructureDefaultTask,
         * although it's not necessary for InstallVirtualEnvironmentTask because
         * GetProbedTagsTask will get the tags.
         */
        getSavedTags(pythonDetails, editablePythonAbiContainer, supportedAbiFormatsFile);
    }

After recompiling and doing ./gradlew publishPluginMavenPublicationToMavenLocal plugin seem to work fine locally.

realill avatar Feb 09 '21 17:02 realill

First is to use JDK8, problem does not occur there.

Tried with jdk8 - same issue

alexogar avatar Feb 09 '21 21:02 alexogar