Ejemplo n.º 1
0
        private void StartInterpreter_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var view    = (EnvironmentView)e.Parameter;
            var factory = view.Factory;

            var psi = new ProcessStartInfo();

            psi.UseShellExecute = false;

            psi.FileName = e.Command == EnvironmentPathsExtension.StartInterpreter ?
                           factory.Configuration.InterpreterPath :
                           factory.Configuration.WindowsInterpreterPath;
            psi.WorkingDirectory = factory.Configuration.PrefixPath;

            // TODO: Figure out some other wa to get the project
            //var provider = _service.KnownProviders.OfType<LoadedProjectInterpreterFactoryProvider>().FirstOrDefault();
            //var vsProject = provider == null ?
            //    null :
            //    provider.GetProject(factory);
            IPythonProject project = null;// vsProject == null ? null : vsProject.GetPythonProject();

            if (project != null)
            {
                psi.EnvironmentVariables[factory.Configuration.PathEnvironmentVariable] =
                    string.Join(";", project.GetSearchPaths());
            }
            else
            {
                psi.EnvironmentVariables[factory.Configuration.PathEnvironmentVariable] = string.Empty;
            }

            Process.Start(psi).Dispose();
        }
        /// <summary>
        /// Sets up environment variables before starting the project.
        /// </summary>
        private void SetupEnvironment(StringDictionary environment)
        {
            string pathEnvVar = _project.GetInterpreterFactory().Configuration.PathEnvironmentVariable;

            if (!string.IsNullOrWhiteSpace(pathEnvVar))
            {
                var pythonPath = string.Join(";", _project.GetSearchPaths());
                if (!_pyService.GeneralOptions.ClearGlobalPythonPath)
                {
                    pythonPath += ";" + Environment.GetEnvironmentVariable(pathEnvVar);
                }
                environment[pathEnvVar] = pythonPath;
            }

            string userEnv = _project.GetProperty(PythonConstants.EnvironmentSetting);

            if (userEnv != null)
            {
                foreach (var envVar in userEnv.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var nameValue = envVar.Split(new[] { '=' }, 2);
                    if (nameValue.Length == 2)
                    {
                        environment[nameValue[0]] = nameValue[1];
                    }
                }
            }
        }