Exemplo n.º 1
0
        public IEnumerable <IPackageManager> GetPackageManagers(IPythonInterpreterFactory factory)
        {
            if (ExperimentalOptions.UseCondaPackageManager)
            {
                if (!Directory.Exists(Path.Combine(factory.Configuration.PrefixPath, "conda-meta")))
                {
                    yield break;
                }

                var condaPath = CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath);
                if (string.IsNullOrEmpty(condaPath))
                {
                    // conda.bat is no longer present in a conda 4.4 environment,
                    // so find a global conda.exe to use.
                    condaPath = _latestCondaExe.Value;
                }

                if (string.IsNullOrEmpty(condaPath))
                {
                    yield break;
                }

                IPackageManager pm = null;
                try {
                    pm = new CondaPackageManager(factory, condaPath);
                } catch (NotSupportedException) {
                    pm = null;
                }
                if (pm != null)
                {
                    yield return(pm);
                }
            }
        }
        private IPackageManager TryCreatePackageManager(IPythonInterpreterFactory factory)
        {
            if (factory == null)
            {
                return(null);
            }

            var prefixPath = factory.Configuration.GetPrefixPath();

            if (string.IsNullOrEmpty(prefixPath) ||
                !Directory.Exists(Path.Combine(prefixPath, "conda-meta")))
            {
                return(null);
            }

            var condaPath = CondaUtils.GetCondaExecutablePath(prefixPath);

            if (string.IsNullOrEmpty(condaPath))
            {
                // conda.bat is no longer present in a conda 4.4 environment,
                // so find a global conda.exe to use.
                condaPath = _latestCondaExe.Value;
            }

            if (string.IsNullOrEmpty(condaPath))
            {
                return(null);
            }

            try {
                return(new CondaPackageManager(factory, condaPath));
            } catch (NotSupportedException) {
                return(null);
            }
        }
Exemplo n.º 3
0
        internal static string GetLatestCondaExecutablePath(IEnumerable <IPythonInterpreterFactory> factories)
        {
            var condaPaths = factories
                             .Select(factory => CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath, allowBatch: false))
                             .Where(path => !string.IsNullOrEmpty(path))
                             .OrderByDescending(path => GetCondaVersion(path));

            return(condaPaths.FirstOrDefault());
        }
Exemplo n.º 4
0
 private IPackageManager CreatePackageManager()
 {
     if (ExperimentalOptions.UseCondaPackageManager && !string.IsNullOrEmpty(CondaUtils.GetCondaExecutablePath(Configuration.PrefixPath)))
     {
         return(new CondaPackageManager());
     }
     else
     {
         return(new PipPackageManager());
     }
 }
Exemplo n.º 5
0
 public CondaPackageManager(
     IPythonInterpreterFactory factory,
     string condaPath
     )
 {
     _factory           = factory;
     _installedPackages = new List <PackageSpec>();
     _availablePackages = new List <PackageSpec>();
     _condaPath         = condaPath ?? CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath);
     _historyPath       = Path.Combine(_factory.Configuration.PrefixPath, "conda-meta", "history");
 }
Exemplo n.º 6
0
        private static string GetLatestCondaExecutablePath(IServiceProvider serviceProvider, IEnumerable <IPythonInterpreterFactory> factories)
        {
            var condaPaths = factories
                             .Select(factory => new {
                PrefixPath = factory.Configuration.PrefixPath,
                ExePath    = CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath, allowBatch: false)
            })
                             .Where(obj => !string.IsNullOrEmpty(obj.ExePath))
                             .OrderByDescending(obj => GetCondaVersion(obj.PrefixPath, obj.ExePath));

            return(condaPaths.FirstOrDefault()?.ExePath);
        }
Exemplo n.º 7
0
 public CondaPackageManager(
     IPythonInterpreterFactory factory,
     string condaPath
     )
 {
     _factory           = factory;
     _installedPackages = new List <PackageSpec>();
     _availablePackages = new List <PackageSpec>();
     _condaPath         = condaPath ?? CondaUtils.GetCondaExecutablePath(factory.Configuration.GetPrefixPath());
     if (!File.Exists(_condaPath))
     {
         throw new NotSupportedException();
     }
     _historyPath = Path.Combine(_factory.Configuration.GetPrefixPath(), "conda-meta", "history");
 }
Exemplo n.º 8
0
        public IEnumerable <IPackageManager> GetPackageManagers(IPythonInterpreterFactory factory)
        {
            IPackageManager pm = null;
            string          condaPath;

            if (ExperimentalOptions.UseCondaPackageManager &&
                !string.IsNullOrEmpty(condaPath = CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath)))
            {
                try {
                    pm = new CondaPackageManager(factory, condaPath);
                } catch (NotSupportedException) {
                    pm = null;
                }
                if (pm != null)
                {
                    yield return(pm);
                }
            }
        }
        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.º 10
0
        public void SetInterpreterFactory(IPythonInterpreterFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (!File.Exists(factory.Configuration?.InterpreterPath))
            {
                throw new NotSupportedException();
            }

            _factory     = factory;
            _condaPath   = CondaUtils.GetCondaExecutablePath(factory.Configuration.PrefixPath);
            _historyPath = Path.Combine(_factory.Configuration.PrefixPath, "conda-meta", "history");

            if (_historyWatcher != null)
            {
                // Watch the conda-meta/history file, which is updated after
                // a package is installed or uninstalled successfully.
                // Note: conda packages don't all install under lib/site-packages.
                try {
                    _historyWatcher.Path = Path.GetDirectoryName(_historyPath);
                    _historyWatcher.EnableRaisingEvents = true;
                } catch (ArgumentException) {
                } catch (IOException) {
                }
            }

            Task.Delay(100).ContinueWith(async t => {
                try {
                    await UpdateIsReadyAsync(false, CancellationToken.None);
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
                }
            }).DoNotWait();
        }