Example #1
0
  @Override
  protected Throwable exec(File f) {
    System.out.println(org.python.pydev.shared_core.string.StringUtils.format("Running: %s", f));
    Tuple<String, String> output =
        new SimpleIronpythonRunner()
            .runAndGetOutput(
                new String[] {
                  TestDependent.IRONPYTHON_EXE,
                  "-u",
                  IInterpreterManager.IRONPYTHON_DEFAULT_INTERNAL_SHELL_VM_ARGS,
                  FileUtils.getFileAbsolutePath(f)
                },
                f.getParentFile(),
                null,
                null,
                "utf-8");

    System.out.println(
        org.python.pydev.shared_core.string.StringUtils.format(
            "stdout:%s\nstderr:%s", output.o1, output.o2));

    if (output.o2.toLowerCase().indexOf("failed") != -1
        || output.o2.toLowerCase().indexOf("traceback") != -1) {
      throw new AssertionError(output.toString());
    }
    return null;
  }
Example #2
0
 /** @return a tuple with the process created and a string representation of the cmdarray. */
 public Tuple<Process, String> run(
     String[] cmdarray, File workingDir, IPythonNature nature, IProgressMonitor monitor) {
   if (monitor == null) {
     monitor = new NullProgressMonitor();
   }
   String executionString = getArgumentsAsStr(cmdarray);
   monitor.setTaskName("Executing: " + executionString);
   monitor.worked(5);
   Process process = null;
   try {
     monitor.setTaskName("Making pythonpath environment..." + executionString);
     String[] envp = null;
     if (nature != null) {
       envp =
           getEnvironment(
               nature,
               nature.getProjectInterpreter(),
               nature.getRelatedInterpreterManager()); // Don't remove as it *should* be updated
       // based on the nature)
     }
     // Otherwise, use default (used when configuring the interpreter for instance).
     monitor.setTaskName("Making exec..." + executionString);
     if (workingDir != null) {
       if (!workingDir.isDirectory()) {
         throw new RuntimeException(
             org.python.pydev.shared_core.string.StringUtils.format(
                 "Working dir must be an existing directory (received: %s)", workingDir));
       }
     }
     process = createProcess(cmdarray, envp, workingDir);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return new Tuple<Process, String>(process, executionString);
 }
Example #3
0
 private void compare(Integer[] is, ArrayList<Integer> offsets) {
   for (int i = 0; i < is.length; i++) {
     if (!is[i].equals(offsets.get(i))) {
       fail(
           org.python.pydev.shared_core.string.StringUtils.format(
               "%s != %s (%s)",
               is[i], offsets.get(i), Arrays.deepToString(is) + " differs from " + offsets));
     }
   }
 }
Example #4
0
  /** Actually remove the python nature from the project. */
  public void run(IAction action) {
    if (selectedProject == null) {
      return;
    }

    if (!MessageDialog.openConfirm(
        null,
        "Confirm Remove Pydev Nature",
        org.python.pydev.shared_core.string.StringUtils.format(
            "Are you sure that you want to remove the Pydev nature from %s?",
            selectedProject.getName()))) {
      return;
    }

    try {
      PythonNature.removeNature(selectedProject, null);
    } catch (Throwable e) {
      Log.log(e);
    }
  }
Example #5
0
  public List<IMessage> getMessages(
      SourceModule module,
      IDocument document,
      IProgressMonitor monitor,
      IAnalysisPreferences prefs) {
    try {

      if (prefs.getSeverityForType(IAnalysisPreferences.TYPE_PEP8) < IMarker.SEVERITY_WARNING) {
        return messages;
      }
      this.prefs = prefs;
      this.document = document;
      messageToIgnore = prefs.getRequiredMessageToIgnore(IAnalysisPreferences.TYPE_PEP8);
      File pep8Loc = JythonModules.getPep8Location();

      if (pep8Loc == null) {
        Log.log("Unable to get pep8 module.");
        return messages;
      }

      IAdaptable projectAdaptable = prefs.getProjectAdaptable();
      if (AnalysisPreferencesPage.useSystemInterpreter(projectAdaptable)) {
        String parameters = AnalysisPreferencesPage.getPep8CommandLineAsStr(projectAdaptable);
        String output =
            PyFormatStd.runWithPep8BaseScript(document.get(), parameters, "pep8.py", "");
        List<String> splitInLines = StringUtils.splitInLines(output, false);

        for (String line : splitInLines) {
          try {
            List<String> lst = StringUtils.split(line, ':', 4);
            int lineNumber = Integer.parseInt(lst.get(1));
            int offset = Integer.parseInt(lst.get(2)) - 1;
            String text = lst.get(3);
            this.reportError(lineNumber, offset, text, null);
          } catch (Exception e) {
            Log.log("Error parsing line: " + line, e);
          }
        }
        return messages;
      }

      String[] pep8CommandLine = AnalysisPreferencesPage.getPep8CommandLine(projectAdaptable);
      FastStringBuffer args = new FastStringBuffer(pep8CommandLine.length * 20);
      for (String string : pep8CommandLine) {
        args.append(',').append("r'").append(string).append('\'');
      }

      // It's important that the interpreter is created in the Thread and not outside the thread
      // (otherwise
      // it may be that the output ends up being shared, which is not what we want.)
      boolean useConsole = AnalysisPreferencesPage.useConsole(projectAdaptable);
      IPythonInterpreter interpreter = JythonPlugin.newPythonInterpreter(useConsole, false);
      String file = StringUtils.replaceAllSlashes(module.getFile().getAbsolutePath());
      interpreter.set("visitor", this);

      List<String> splitInLines = StringUtils.splitInLines(document.get());
      interpreter.set("lines", splitInLines);
      PyObject tempReportError = reportError;
      if (tempReportError != null) {
        interpreter.set("ReportError", tempReportError);
      } else {
        interpreter.set("ReportError", Py.None);
      }
      PyObject pep8Module = JythonModules.getPep8Module(interpreter);
      interpreter.set("pep8", pep8Module);

      String formatted = StringUtils.format(EXECUTE_PEP8, file, args.toString(), file);
      interpreter.exec(formatted);
      if (reportError == null) {
        synchronized (lock) {
          if (reportError == null) {
            reportError = interpreter.get("ReportError");
          }
        }
      }

    } catch (Exception e) {
      Log.log("Error analyzing: " + module, e);
    }

    return messages;
  }
Example #6
0
 public PydevRootPrefs() {
   setDescription(
       org.python.pydev.shared_core.string.StringUtils.format(
           "PyDev version: %s", PydevPlugin.version));
 }