Exemple #1
0
        internal static bool ExcludeInterpreter(InterpreterConfiguration config, InterpreterFilter excludeInterpreters = InterpreterFilter.None)
        {
            if (excludeInterpreters == InterpreterFilter.None)
            {
                return(false);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeVirtualEnv) && VirtualEnv.IsPythonVirtualEnv(config.GetPrefixPath()))
            {
                return(true);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeCondaEnv) && CondaUtils.IsCondaEnvironment(config.GetPrefixPath()))
            {
                return(true);
            }

            if (excludeInterpreters.HasFlag(InterpreterFilter.ExcludeIronpython) && config.IsIronPython())
            {
                return(true);
            }

            return(false);
        }
Exemple #2
0
        private async Task CreateVirtualEnvironmentAsync(ITaskHandler taskHandler)
        {
            IPythonInterpreterFactory factory = null;

            bool failed     = true;
            var  baseInterp = _registry.FindInterpreter(_baseInterpreter);

            try {
                factory = await VirtualEnv.CreateAndAddFactory(
                    _site,
                    _registry,
                    _options,
                    _project,
                    _workspace,
                    _virtualEnvPath,
                    baseInterp,
                    _registerAsCustomEnv,
                    _customEnvName,
                    _useVEnv
                    );

                if (factory != null)
                {
                    if (_installReqs && File.Exists(_reqsPath))
                    {
                        await InstallPackagesAsync(taskHandler, factory);
                    }

                    await _site.GetUIThread().InvokeTask(async() => {
                        // Note that for a workspace, VirtualEnv.CreateAndAddFactory
                        // takes care of updating PythonSettings.json, as that is
                        // required in order to obtain the factory. So no need to do
                        // anything here for workspace.
                        if (_project != null)
                        {
                            _project.AddInterpreter(factory.Configuration.Id);
                            if (_setAsCurrent)
                            {
                                _project.SetInterpreterFactory(factory);
                            }
                        }

                        if (_setAsDefault && _options != null)
                        {
                            _options.DefaultInterpreter = factory;
                        }

                        if (_viewInEnvWindow)
                        {
                            await InterpreterListToolWindow.OpenAtAsync(_site, factory);
                        }
                    });
                }

                failed = false;
            } finally {
                _logger?.LogEvent(PythonLogEvent.CreateVirtualEnv, new CreateVirtualEnvInfo()
                {
                    Failed = failed,
                    InstallRequirements = _installReqs,
                    UseVEnv             = _useVEnv,
                    Global                 = _registerAsCustomEnv,
                    LanguageVersion        = baseInterp?.Configuration?.Version.ToString() ?? "",
                    Architecture           = baseInterp?.Configuration?.ArchitectureString ?? "",
                    SetAsDefault           = _setAsDefault,
                    SetAsCurrent           = _setAsCurrent,
                    OpenEnvironmentsWindow = _viewInEnvWindow,
                });
            }

            taskHandler?.Progress.Report(new TaskProgressData()
            {
                CanBeCanceled   = false,
                ProgressText    = Strings.VirtualEnvStatusCenterCreateProgressCompleted,
                PercentComplete = 100,
            });
        }
        private void CustomEnvironmentPrefixPathChanged()
        {
            if (IsCustomInterpreter)
            {
                if (Directory.Exists(PrefixPath))
                {
                    IsCustomPrefixPathValid = true;

                    var config = VirtualEnv.FindInterpreterConfiguration(null, PrefixPath, RegistryService);
                    if (config != null && File.Exists(config.InterpreterPath))
                    {
                        var baseInterp = _allGlobalInterpreters.FirstOrDefault(v => v.Id == config.Id);

                        IsRegisterCustomEnvEnabled = SelectedProject != null;
                        RegisterCustomEnv          = SelectedProject == null;
                        IsCustomVirtualEnv         = baseInterp != null;
                        IsCustomNotVirtualEnv      = baseInterp == null;

                        SetCustomVariables(config);
                    }
                    else
                    {
                        IsRegisterCustomEnvEnabled = SelectedProject != null;
                        RegisterCustomEnv          = true;
                        IsCustomNotVirtualEnv      = true;
                        IsCustomVirtualEnv         = false;

                        ClearCustomVariables();

                        AutoDetectFromCustomPrefixPathAsync().DoNotWait();
                    }

                    ValidateCustomData();
                }
                else
                {
                    IsRegisterCustomEnvEnabled = false;
                    RegisterCustomEnv          = false;
                    IsCustomPrefixPathValid    = false;
                    IsCustomNotVirtualEnv      = false;
                    IsCustomVirtualEnv         = false;

                    // For now, we enable but prompt when they click accept
                    //IsAcceptEnabled = false;
                    IsAcceptEnabled = true;

                    ClearCustomVariables();
                }
            }
            else
            {
                IsRegisterCustomEnvEnabled = false;
                RegisterCustomEnv          = false;
                IsCustomPrefixPathValid    = false;
                IsCustomNotVirtualEnv      = false;
                IsCustomVirtualEnv         = false;
                IsAcceptEnabled            = true;

                ClearCustomVariables();
            }
        }