Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with creating a virtualenv. #348

Open
rohit-karthik opened this issue Jan 11, 2021 · 3 comments
Open

Issue with creating a virtualenv. #348

rohit-karthik opened this issue Jan 11, 2021 · 3 comments

Comments

@rohit-karthik
Copy link

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
Copy link

realill commented Feb 8, 2021

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
Copy link

realill commented Feb 9, 2021

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
Copy link

alexogar commented Feb 9, 2021

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

Tried with jdk8 - same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants