Search in sources :

Example 1 with InvalidSdkException

use of com.jetbrains.python.sdk.InvalidSdkException in project intellij-community by JetBrains.

the class PySkeletonGenerator method generateBuiltinSkeletons.

public void generateBuiltinSkeletons(@NotNull Sdk sdk) throws InvalidSdkException {
    //noinspection ResultOfMethodCallIgnored
    new File(mySkeletonsPath).mkdirs();
    String binaryPath = sdk.getHomePath();
    if (binaryPath == null)
        throw new InvalidSdkException("Broken home path for " + sdk.getName());
    long startTime = System.currentTimeMillis();
    final ProcessOutput runResult = getProcessOutput(new File(binaryPath).getParent(), new String[] { binaryPath, PythonHelpersLocator.getHelperPath(GENERATOR3), // output dir
    "-d", // output dir
    mySkeletonsPath, // for builtins
    "-b" }, PythonSdkType.getVirtualEnvExtraEnv(binaryPath), MINUTE * 5);
    runResult.checkSuccess(LOG);
    LOG.info("Rebuilding builtin skeletons took " + (System.currentTimeMillis() - startTime) + " ms");
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) SkeletonVersionChecker.fromVersionString(com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with InvalidSdkException

use of com.jetbrains.python.sdk.InvalidSdkException in project intellij-community by JetBrains.

the class PySkeletonGenerator method listBinaries.

@NotNull
public ListBinariesResult listBinaries(@NotNull Sdk sdk, @NotNull String extraSysPath) throws InvalidSdkException {
    final String homePath = sdk.getHomePath();
    final long startTime = System.currentTimeMillis();
    if (homePath == null)
        throw new InvalidSdkException("Broken home path for " + sdk.getName());
    final String parentDir = new File(homePath).getParent();
    List<String> cmd = new ArrayList<>(Arrays.asList(homePath, PythonHelpersLocator.getHelperPath(GENERATOR3), "-v", "-L"));
    if (!StringUtil.isEmpty(extraSysPath)) {
        cmd.add("-s");
        cmd.add(extraSysPath);
    }
    final ProcessOutput process = getProcessOutput(parentDir, ArrayUtil.toStringArray(cmd), PythonSdkType.getVirtualEnvExtraEnv(homePath), // see PY-3898
    MINUTE * 4);
    LOG.info("Retrieving binary module list took " + (System.currentTimeMillis() - startTime) + " ms");
    if (process.getExitCode() != 0) {
        final StringBuilder sb = new StringBuilder("failed to run ").append(GENERATOR3).append(" for ").append(homePath);
        if (process.isTimeout()) {
            sb.append(": timed out.");
        } else {
            sb.append(", exit code ").append(process.getExitCode()).append(", stderr: \n-----\n");
            for (String line : process.getStderrLines()) {
                sb.append(line).append("\n");
            }
            sb.append("-----");
        }
        throw new InvalidSdkException(sb.toString());
    }
    final List<String> lines = process.getStdoutLines();
    if (lines.size() < 1) {
        throw new InvalidSdkException("Empty output from " + GENERATOR3 + " for " + homePath);
    }
    final Iterator<String> iter = lines.iterator();
    final int generatorVersion = fromVersionString(iter.next().trim());
    final Map<String, PySkeletonRefresher.PyBinaryItem> binaries = Maps.newHashMap();
    while (iter.hasNext()) {
        final String line = iter.next();
        int cutpos = line.indexOf('\t');
        if (cutpos >= 0) {
            String[] strs = line.split("\t");
            String moduleName = strs[0];
            String path = strs[1];
            int length = Integer.parseInt(strs[2]);
            int lastModified = Integer.parseInt(strs[3]);
            binaries.put(moduleName, new PySkeletonRefresher.PyBinaryItem(moduleName, path, length, lastModified));
        } else {
            // but don't die yet
            LOG.error("Bad binaries line: '" + line + "', SDK " + homePath);
        }
    }
    return new ListBinariesResult(generatorVersion, binaries);
}
Also used : SkeletonVersionChecker.fromVersionString(com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString) ProcessOutput(com.intellij.execution.process.ProcessOutput) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InvalidSdkException

use of com.jetbrains.python.sdk.InvalidSdkException in project intellij-community by JetBrains.

the class PySkeletonRefresher method getSkeletonsPath.

/**
   * Creates if needed all path(s) used to store skeletons of its SDK.
   *
   * @return path name of skeleton dir for the SDK, guaranteed to be already created.
   */
@NotNull
public String getSkeletonsPath() throws InvalidSdkException {
    if (mySkeletonsPath == null) {
        mySkeletonsPath = PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), mySdk.getHomePath());
        final File skeletonsDir = new File(mySkeletonsPath);
        if (!skeletonsDir.exists() && !skeletonsDir.mkdirs()) {
            throw new InvalidSdkException("Can't create skeleton dir " + String.valueOf(mySkeletonsPath));
        }
    }
    return mySkeletonsPath;
}
Also used : InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with InvalidSdkException

use of com.jetbrains.python.sdk.InvalidSdkException in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method getFixTask.

/**
   * Returns fix task that is used to generate stubs
   *
   * @param fileToRunTaskIn file where task should run
   * @return task itself
   */
@NotNull
public Backgroundable getFixTask(@NotNull final PsiFile fileToRunTaskIn) {
    final Project project = fileToRunTaskIn.getProject();
    final String folder = fileToRunTaskIn.getContainingDirectory().getVirtualFile().getCanonicalPath();
    return new Task.Backgroundable(project, "Generating skeletons for binary module", false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final List<String> assemblyRefs = new ReadAction<List<String>>() {

                @Override
                protected void run(@NotNull Result<List<String>> result) throws Throwable {
                    result.setResult(collectAssemblyReferences(fileToRunTaskIn));
                }
            }.execute().getResultObject();
            try {
                final PySkeletonRefresher refresher = new PySkeletonRefresher(project, null, mySdk, null, null, folder);
                if (needBinaryList(myQualifiedName)) {
                    if (!generateSkeletonsForList(refresher, indicator, folder))
                        return;
                } else {
                    //noinspection unchecked
                    refresher.generateSkeleton(myQualifiedName, "", assemblyRefs, Consumer.EMPTY_CONSUMER);
                }
                final VirtualFile skeletonDir;
                skeletonDir = LocalFileSystem.getInstance().findFileByPath(refresher.getSkeletonsPath());
                if (skeletonDir != null) {
                    skeletonDir.refresh(true, true);
                }
            } catch (InvalidSdkException e) {
                LOG.error(e);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PySkeletonRefresher(com.jetbrains.python.sdk.skeletons.PySkeletonRefresher) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadAction(com.intellij.openapi.application.ReadAction) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 InvalidSdkException (com.jetbrains.python.sdk.InvalidSdkException)4 NotNull (org.jetbrains.annotations.NotNull)3 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 SkeletonVersionChecker.fromVersionString (com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString)2 File (java.io.File)2 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Backgroundable (com.intellij.openapi.progress.Task.Backgroundable)1 Project (com.intellij.openapi.project.Project)1 PySkeletonRefresher (com.jetbrains.python.sdk.skeletons.PySkeletonRefresher)1