linkedin / pygradle

Using Gradle to build Python projects
https://github.com/linkedin/pygradle
Apache License 2.0
586 stars 147 forks source link

Issue with creating a virtualenv. #348

Open rohit-karthik opened 3 years ago

rohit-karthik commented 3 years ago

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!

realill commented 3 years ago

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 commented 3 years ago

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.

alexogar commented 3 years ago

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

Tried with jdk8 - same issue