Package org.python.pydev.plugin.nature

Examples of org.python.pydev.plugin.nature.PythonNature


public class DjangoWar extends DjangoAction {

    public void run(IAction action) {
        try {
            PythonNature nature = PythonNature.getPythonNature(selectedProject);
            if (nature.getInterpreterType() != IInterpreterManager.INTERPRETER_TYPE_JYTHON) {
                MessageDialog.openInformation(null, "Can't create WAR",
                        "Creation of WAR packages is only supported on Jython");
                return;
            }
            String projectPythonPath = nature.getPythonPathNature().getOnlyProjectPythonPathStr(true);
            String javaLibs = null;
            for (String path : projectPythonPath.split("\\|")) {
                if (path.endsWith(".jar")) {
                    if (javaLibs == null) {
                        javaLibs = path;
View Full Code Here


    /**
     * May be used to run some command that uses the manage.py file.
     */
    @SuppressWarnings("restriction")
    public ILaunch launchDjangoCommand(final String command, boolean refreshAndShowMessageOnFinish) {
        PythonNature nature = PythonNature.getPythonNature(selectedProject);
        if (nature == null) {
            MessageDialog.openError(PyAction.getShell(), "PyDev nature not found",
                    "Unable to perform action because the Pydev nature is not properly set.");
            return null;
        }
        IPythonPathNature pythonPathNature = nature.getPythonPathNature();
        String manageVarible = null;
        Map<String, String> variableSubstitution = null;
        try {
            variableSubstitution = pythonPathNature.getVariableSubstitution();
            manageVarible = variableSubstitution.get(DjangoConstants.DJANGO_MANAGE_VARIABLE);
View Full Code Here

                dialog.open();

                Object object = dialog.getFirstResult();
                if ((object != null) && (object instanceof IProject)) {
                    IProject project = (IProject) object;
                    PythonNature pythonNature = PythonNature.getPythonNature(project);
                    if (pythonNature == null) {
                        // The project does not have an associated python nature...
                        String msg = "The selected project must have the python nature associated.";
                        String title = "Invalid project (no python nature associated).";
                        ErrorDialog.openError(getShell(), title, msg,
View Full Code Here

            if (resource == null) {
                setErrorMessage("Invalid project");
                result = false;
            } else if (resource instanceof IProject) {
                IProject project = (IProject) resource;
                PythonNature nature = PythonNature.getPythonNature(project);
                if (nature == null) {
                    setErrorMessage("Invalid project (no python nature associated).");
                    result = false;
                }
            }
View Full Code Here

*/
public class PySyntaxChecker extends PyDevBuilderVisitor {

    @Override
    public void visitChangedResource(IResource resource, ICallback0<IDocument> document, IProgressMonitor monitor) {
        PythonNature nature = getPythonNature(resource);
        if (nature == null) {
            return;
        }

        if (PyDevBuilderPrefPage.getAnalyzeOnlyActiveEditor()) {
View Full Code Here

                    IResource resource = workspace.getRoot().findMember(fProjectName);

                    boolean enabled = false;
                    if ((resource != null) && (resource instanceof IProject)) {
                        IProject project = (IProject) resource;
                        PythonNature nature = PythonNature.getPythonNature(project);
                        enabled = (nature != null);
                    }

                    fMainModuleBrowseButton.setEnabled(enabled);
                }
View Full Code Here

            } else {
                //Get from the project
                try {
                    //could throw core exception if project does not exist.
                    IProject project = PythonRunnerConfig.getProjectFromConfiguration(configuration);
                    PythonNature nature = PythonNature.getPythonNature(project);
                    if (nature != null) {
                        manager = PydevPlugin.getInterpreterManager(nature);
                    }
                } catch (Exception e) {
                    Log.log(e);
View Full Code Here

    IProject project = ProjectUtils.getProject(projectName);
    IDocument doc = ProjectUtils.getDocument(project, fileName);
    final File file = new File(ProjectUtils.getFilePath(project, fileName));

    PythonNature nature = PythonNature.getPythonNature(project);
    PySelection selection = new PySelection(
        doc, new TextSelection(doc, offset, length));

    // needed for findAllOccurrences
    PyEdit pyEdit = new PyEdit(){
      public File getEditorFile() {
        return file;
      }
    };
    RefactoringRequest request = new RefactoringRequest(
        file, selection, null, nature, pyEdit);

    ArrayList<Position> results = new ArrayList<Position>();

    String context = commandLine.getValue(Options.CONTEXT_OPTION);
    // find references
    if (CONTEXT_REFERENCES.equals(context)){
      // for some reason the pydev project's path isn't initialized properly
      // leading to findAllOccurrences only finding results from the current
      // file. This seems to be plenty fast for my reasonably sized project, so
      // hopefully it won't be a bottleneck for others.
      PythonNature pythonNature = PythonNature.getPythonNature(project);
      pythonNature.rebuildPath();

      request.fillInitialNameAndOffset();
      IPyRefactoring2 pyRefactoring = (IPyRefactoring2)
        AbstractPyRefactoring.getPyRefactoring();
      Map<Tuple<String,File>, HashSet<ASTEntry>> refs =
View Full Code Here

    String projectName = commandLine.getValue(Options.PROJECT_OPTION);
    String interpreterNameOrPath = commandLine.getValue("i");
    String version = commandLine.getValue(Options.VERSION_OPTION);

    IProject project = ProjectUtils.getProject(projectName);
    PythonNature nature = PythonNature.getPythonNature(project);
    if (nature == null){
      throw new RuntimeException(
          Services.getMessage("python.missing.nature"));
    }

    IInterpreterInfo interpreter = null;
    IInterpreterManager manager = nature.getRelatedInterpreterManager();
    IInterpreterInfo[] existing = manager.getInterpreterInfos();
    for (IInterpreterInfo info : existing){
      if (info.getName().equals(interpreterNameOrPath) ||
          info.getExecutableOrJar().equals(interpreterNameOrPath))
      {
        interpreter = info;
        break;
      }
    }

    File path = new File(interpreterNameOrPath);
    if (interpreter == null && path.exists() && path.isFile()){
      HashSet<String> skip = new HashSet<String>();
      for (IInterpreterInfo info : existing){
        skip.add(info.getExecutableOrJar());
      }
      interpreter = manager.createInterpreterInfo(
          interpreterNameOrPath, new NullProgressMonitor(), false);
      interpreter.setName(FileUtils.getBaseName(interpreterNameOrPath));
      IInterpreterInfo[] updated = new IInterpreterInfo[existing.length + 1];
      System.arraycopy(existing, 0, updated, 0, existing.length);
      updated[updated.length - 1] = interpreter;
      manager.setInfos(updated, skip, new NullProgressMonitor());
    }else if (interpreter == null){
      throw new RuntimeException(Services.getMessage(
            "python.interpreter.not.found", interpreterNameOrPath));
    }

    if (version == null){
      version = nature.getVersion();
    }

    // ensure the version is valid for the new interpreter
    ArrayList<String> grammars = new ArrayList<String>();
    String[] parts = StringUtils.split(interpreter.getVersion(), ".");
    double iversion = Double.parseDouble(parts[0] + '.' + parts[1]);
    for (String grammar : IPythonNature.Versions.ALL_PYTHON_VERSIONS){
      grammar = grammar.replace("python ", "");
      double gversion = Double.parseDouble(grammar);
      if (gversion <= iversion &&
          grammar.charAt(0) == interpreter.getVersion().charAt(0))
      {
        grammars.add(grammar);
      }
    }
    if (!grammars.contains(version)){
      Collections.sort(grammars);
      version = grammars.get(grammars.size() - 1);
    }

    nature.setVersion(version, interpreter.getName());

    return Services.getMessage("python.interpreter.set", projectName);
  }
View Full Code Here

  public Object execute(CommandLine commandLine)
    throws Exception
  {
    String projectName = commandLine.getValue(Options.PROJECT_OPTION);
    IProject project = ProjectUtils.getProject(projectName);
    PythonNature nature = PythonNature.getPythonNature(project);
    ArrayList<String> grammars = new ArrayList<String>();
    if (nature != null){
      IInterpreterInfo interpreter = nature.getProjectInterpreter();
      if (interpreter != null){
        String version = interpreter.getVersion();
        String[] parts = StringUtils.split(version, ".");
        double iversion = Double.parseDouble(parts[0] + '.' + parts[1]);
        for (String grammar : IPythonNature.Versions.ALL_PYTHON_VERSIONS){
View Full Code Here

TOP

Related Classes of org.python.pydev.plugin.nature.PythonNature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.