private void DiscoverInterpreterFactories()
        {
            if (Volatile.Read(ref _ignoreNotifications) > 0)
            {
                return;
            }

            DiscoveryStarted?.Invoke(this, EventArgs.Empty);

            // Discover the available interpreters...
            bool anyChanged = false;

            List <PythonInterpreterInformation> found = null;

            try {
                // Try to find an existing root conda installation
                // If the future we may decide to install a private installation of conda/miniconda
                var globalFactories  = _globalProvider.GetInterpreterFactories().ToList();
                var mainCondaExePath = CondaUtils.GetLatestCondaExecutablePath(globalFactories);
                if (mainCondaExePath != null)
                {
                    found = FindCondaEnvironments(mainCondaExePath).ToList();
                }
            } catch (ObjectDisposedException) {
                // We are aborting, so silently return with no results.
                return;
            }

            var uniqueIds = new HashSet <string>(found.Select(i => i.Configuration.Id));

            // Then update our cached state with the lock held.
            lock (_factories) {
                foreach (var info in found.MaybeEnumerate())
                {
                    PythonInterpreterInformation existingInfo;
                    if (!_factories.TryGetValue(info.Configuration.Id, out existingInfo) ||
                        info.Configuration != existingInfo.Configuration)
                    {
                        _factories[info.Configuration.Id] = info;
                        anyChanged = true;
                    }
                }

                // Remove any factories we had before and no longer see...
                foreach (var unregistered in _factories.Keys.Except(uniqueIds).ToArray())
                {
                    _factories.Remove(unregistered);
                    anyChanged = true;
                }
            }

            if (anyChanged)
            {
                OnInterpreterFactoriesChanged();
            }
        }
        private void FindCondaEnvironments(List <PythonInterpreterInformation> envs)
        {
            // Try to find an existing root conda installation
            // If the future we may decide to install a private installation of conda/miniconda
            var globalFactories  = _globalProvider.GetInterpreterFactories().ToList();
            var mainCondaExePath = CondaUtils.GetLatestCondaExecutablePath(globalFactories);

            if (mainCondaExePath != null)
            {
                envs.AddRange(FindCondaEnvironments(mainCondaExePath));
            }
        }
        private string GetMainCondaExecutablePath()
        {
            // Try to find an existing root conda installation
            // If the future we may decide to install a private installation of conda/miniconda
            string mainCondaExePath = null;
            var    globalFactories  = _globalProvider.GetInterpreterFactories().ToList();

            foreach (var factory in globalFactories)
            {
                var condaPath = CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath, allowBatch: false);
                if (!string.IsNullOrEmpty(condaPath))
                {
                    // TODO: need to pick the newest conda.exe on the machine,
                    // not just the first one found.
                    // Unfortunately, conda.exe doesn't have a version resource,
                    // we'll need to figure some other way to determine conda version.
                    mainCondaExePath = condaPath;
                    break;
                }
            }

            return(mainCondaExePath);
        }
Exemplo n.º 4
0
        public AutoDetectedLatestCondaLocator(
            [Import] CPythonInterpreterFactoryProvider globalProvider,
            [Import(typeof(SVsServiceProvider), AllowDefault = true)] IServiceProvider site = null
            )
        {
            _globalProvider = globalProvider;
            _site           = site;

            // This can be slow, if there are 2 or more global conda installations
            // (some conda versions have long startup time), so we only fetch it once.
            _latestCondaExe = new Lazy <string>(() => GetLatestCondaExecutablePath(_site, _globalProvider.GetInterpreterFactories()));
        }
Exemplo n.º 5
0
        public CPythonCondaPackageManagerProvider(
            [Import] CPythonInterpreterFactoryProvider globalProvider
            )
        {
            _globalProvider = globalProvider;

            // This can be slow, if there are 2 or more global conda installations
            // (some conda versions have long startup time), so we only fetch it once.
            _latestCondaExe = new Lazy <string>(() => CondaUtils.GetLatestCondaExecutablePath(_globalProvider.GetInterpreterFactories()));
        }