Package org.python.pydev.plugin.nature

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


            //OK, structure created, now, let's open mod1.py with a PyEdit so that the tests can begin...

            //create the contents and open the editor
            mod1.create(new ByteArrayInputStream(mod1Contents.getBytes()), true, monitor);

            PythonNature nature = PythonNature.getPythonNature(project);

            waitForNatureToBeRecreated(nature);

            editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
        } else {
View Full Code Here


        PydevPlugin.setIronpythonInterpreterManager(interpreterManager);
    }

    @Override
    protected PythonNature createNature() {
        return new PythonNature() {
            @Override
            public int getInterpreterType() throws CoreException {
                return IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON;
            }
View Full Code Here

        PyCodeCompletion.onCompletionRecursionException = null;
    }

    @Override
    protected PythonNature createNature() {
        return new PythonNature() {
            @Override
            public int getInterpreterType() throws CoreException {
                return IInterpreterManager.INTERPRETER_TYPE_PYTHON;
            }
View Full Code Here

        assertTrue(arrayContains(argv, PythonRunnerConfig.getRunFilesScript()));
        assertTrue(arrayContains(argv, mod1.getLocation().toOSString()));
    }

    public void testPythonCommandLine() throws Exception {
        PythonNature nature = PythonNature.getPythonNature(mod1);

        // Create a temporary variable for testing
        IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager();
        IValueVariable myCustomVariable = variableManager.newValueVariable("pydev_python_runner_config_test_var", "",
                true, "my_custom_value");
        variableManager.addVariables(new IValueVariable[] { myCustomVariable });

        try {
            IInterpreterManager manager = PydevPlugin.getPythonInterpreterManager(true);
            InterpreterInfo info = (InterpreterInfo) manager.getDefaultInterpreterInfo(false);
            info.setEnvVariables(new String[] { "MY_CUSTOM_VAR_FOR_TEST=FOO", "MY_CUSTOM_VAR_FOR_TEST2=FOO2",
                    "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}" });

            // Make sure variable hasn't been expanded too early
            assertTrue(arrayContains(info.getEnvVariables(),
                    "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}"));

            PythonRunnerConfig runnerConfig = createConfig();
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=FOO2"));
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));

            String[] argv = runnerConfig.getCommandLine(false);
            assertFalse(arrayContains(argv, PythonRunnerConfig.getRunFilesScript()));
            assertTrue(arrayContains(argv, mod1.getLocation().toOSString()));

            nature.setVersion(IPythonNature.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
            assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), nature.getProjectInterpreter()
                    .getExecutableOrJar());
            runnerConfig = createConfig();
            argv = runnerConfig.getCommandLine(false);
            assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), argv[0]);

            IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();

            InterpreterInfo info2 = new InterpreterInfo(IPythonNature.PYTHON_VERSION_2_6, "c:\\interpreter\\py25.exe",
                    new ArrayList<String>());
            interpreterManager.setInfos(new IInterpreterInfo[] { info, info2 }, null, null);

            nature.setVersion(IPythonNature.PYTHON_VERSION_LATEST, "c:\\interpreter\\py25.exe");
            assertEquals("c:\\interpreter\\py25.exe", nature.getProjectInterpreter().getExecutableOrJar());
            runnerConfig = createConfig();
            argv = runnerConfig.getCommandLine(false);
            assertEquals("c:\\interpreter\\py25.exe", argv[0]);
            nature.setVersion(IPythonNature.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);

            ILaunchConfiguration config;
            config = new LaunchShortcut().createDefaultLaunchConfiguration(FileOrResource
                    .createArray(new IResource[] { mod1 }));
            ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("VAR_SPECIFIED_IN_LAUNCH", "BAR");
            map.put("MY_CUSTOM_VAR_FOR_TEST2", "BAR2"); //The one in the launch configuration always has preference.
            workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
            config = workingCopy.doSave();

            runnerConfig = new PythonRunnerConfig(config, ILaunchManager.RUN_MODE, PythonRunnerConfig.RUN_REGULAR);
            assertTrue(arrayContains(runnerConfig.envp, "VAR_SPECIFIED_IN_LAUNCH=BAR"));
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=BAR2"));
            assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));
        } catch (Throwable e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            //restore the default!
            nature.setVersion(IPythonNature.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
            variableManager.removeVariables(new IValueVariable[] { myCustomVariable });
        }
    }
View Full Code Here

                int i = 0;
                for (Tuple<List<ModulesKey>, IPythonNature> file : references) {
                    i++;
                    request.communicateWork(com.aptana.shared_core.string.StringUtils.format("Analyzing %s (%s of %s)", file.o2.getProject(), i,
                            total));
                    PythonNature nature = (PythonNature) file.o2;
                    if (nature != null) {
                        if (!nature.startRequests()) {
                            continue;
                        }
                        try {
                            for (ModulesKey key : file.o1) {
                                IProjectModulesManager modulesManager = (IProjectModulesManager) nature.getAstManager()
                                        .getModulesManager();

                                request.checkCancelled();
                                String modName = key.name;

                                if (modName != null) {
                                    if (!request.moduleName.equals(modName)) {
                                        //we've already checked the module from the request...

                                        request.checkCancelled();
                                        IModule module = modulesManager
                                                .getModuleInDirectManager(modName, nature, false);

                                        if (module instanceof SourceModule) {

                                            request.checkCancelled();
                                            List<ASTEntry> entryOccurrences = getOccurrencesInOtherModule(status,
                                                    request.initialName, (SourceModule) module, nature);

                                            if (entryOccurrences.size() > 0) {
                                                addOccurrences(entryOccurrences, key.file, modName);
                                            }
                                        }
                                    }
                                }
                            }
                        } finally {
                            nature.endRequests();
                        }
                    }
                }
            } finally {
                request.popMonitor().done();
View Full Code Here

     * @param path the pythonpath for the new nature
     * @param name the name for the project
     * @return true if the creation was needed and false if it wasn't
     */
    protected boolean restoreProjectPythonPathRefactoring(boolean force, String path, String name) {
        PythonNature n = checkNewNature(name, force);
        if (n != null) {
            natureRefactoring = n;

            ProjectStub projectFromNatureRefactoring = new ProjectStub(name, path, new IProject[0], new IProject[0]);
            setAstManager(path, projectFromNatureRefactoring, natureRefactoring);
View Full Code Here

        return setUpFooModule(line, col, str);
    }

    private RefactoringRequest setUpFooModule(final int line, final int col, String str) {
        String modName = "foo";
        PythonNature natureToAdd = nature;
        return setUpModule(line, col, str, modName, natureToAdd);
    }
View Full Code Here

    @Override
    protected void okPressed() {
        setSelectedFrame(null);
        if (checkboxForCurrentEditor.isEnabled() && checkboxForCurrentEditor.getSelection()) {
            IProject project = this.activeEditor.getProject();
            PythonNature nature = PythonNature.getPythonNature(project);
            natures.add(nature);
            IInterpreterManager relatedInterpreterManager = nature.getRelatedInterpreterManager();
            this.interpreterManager = relatedInterpreterManager;

        } else if (checkboxPython.isEnabled() && checkboxPython.getSelection()) {
            this.interpreterManager = PydevPlugin.getPythonInterpreterManager();
View Full Code Here

            pythonpath.addAll(interpreter.getPythonPath());

            //we need to get the natures matching the one selected in all the projects.
            IWorkspace w = ResourcesPlugin.getWorkspace();
            for (IProject p : w.getRoot().getProjects()) {
                PythonNature nature = PythonNature.getPythonNature(p);
                try {
                    if (nature != null) {
                        if (nature.getRelatedInterpreterManager() == this.interpreterManager) {
                            natures.add(nature);
                            List<String> completeProjectPythonPath = nature.getPythonPathNature()
                                    .getCompleteProjectPythonPath(interpreter, this.interpreterManager);
                            if (completeProjectPythonPath != null) {
                                pythonpath.addAll(completeProjectPythonPath);
                            } else {
                                Log.logInfo("Unable to get pythonpath for project: " + nature.getProject()
                                        + " (initialization not finished).");
                            }
                        }
                    }
                } catch (Exception e) {
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.