Example #1
0
        public static IEnumerable <InterpreterView> GetInterpreters(
            IServiceProvider serviceProvider,
            PythonProjectNode project,
            bool onlyGlobalEnvironments           = false,
            InterpreterFilter excludeInterpreters = InterpreterFilter.None
            )
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var knownProviders = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
            var res            = knownProviders.Configurations
                                 .Where(PythonInterpreterFactoryExtensions.IsUIVisible)
                                 .Where(PythonInterpreterFactoryExtensions.IsRunnable)
                                 .Where(configuration => !ExcludeInterpreter(configuration, excludeInterpreters))
                                 .OrderBy(c => c.Description)
                                 .ThenBy(c => c.Version)
                                 .Select(c => new InterpreterView(c.Id, c.Description, c.InterpreterPath, c.Version.ToString(), c.ArchitectureString, project));

            if (onlyGlobalEnvironments)
            {
                res = res.Where(v => string.IsNullOrEmpty(knownProviders.GetProperty(v.Id, "ProjectMoniker") as string));
            }

            if (project != null)
            {
                res = res.Concat(project.InvalidInterpreterIds
                                 .Select(i => new InterpreterView(i, FormatInvalidId(i), string.Empty, string.Empty, string.Empty, project))
                                 .OrderBy(v => v.Name));
            }

            return(res);
        }
Example #2
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);
        }