Ejemplo n.º 1
0
        internal Dictionary <string, string> GetFullEnvironment(LaunchConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            // Start with global environment, add configured environment,
            // then add search paths.
            var baseEnv = Environment.GetEnvironmentVariables();
            // Clear search paths from the global environment. The launch
            // configuration should include the existing value

            var pathVar = config.Interpreter?.PathEnvironmentVariable;

            if (string.IsNullOrEmpty(pathVar))
            {
                pathVar = "PYTHONPATH";
            }
            baseEnv[pathVar] = string.Empty;

            // TODO: We could introduce a cache so that we don't activate the
            // environment + capture the env variables every time. Not doing this
            // right now to minimize risk/complexity so close to release.
            if (CondaUtils.IsCondaEnvironment(config.Interpreter.GetPrefixPath()))
            {
                var condaExe   = CondaUtils.GetRootCondaExecutablePath(Site);
                var prefixPath = config.Interpreter.GetPrefixPath();
                if (File.Exists(condaExe) && Directory.Exists(prefixPath))
                {
                    var condaEnv = CondaUtils.CaptureActivationEnvironmentVariablesForPrefix(condaExe, prefixPath);
                    baseEnv = PathUtils.MergeEnvironments(baseEnv.AsEnumerable <string, string>(), condaEnv, "Path", pathVar);
                }
            }

            var env = PathUtils.MergeEnvironments(
                baseEnv.AsEnumerable <string, string>(),
                config.GetEnvironmentVariables(),
                "Path", pathVar
                );

            if (config.SearchPaths != null && config.SearchPaths.Any())
            {
                env = PathUtils.MergeEnvironments(
                    env,
                    new[] {
                    new KeyValuePair <string, string>(
                        pathVar,
                        PathUtils.JoinPathList(config.SearchPaths)
                        )
                },
                    pathVar
                    );
            }
            return(env);
        }
Ejemplo n.º 2
0
        private static CondaEnvironmentManager CreateEnvironmentManager()
        {
            if (!PythonPaths.AnacondaVersions.Any())
            {
                Assert.Inconclusive("Anaconda is required.");
            }

            var    version   = PythonPaths.AnacondaVersions.FirstOrDefault();
            string condaPath = CondaUtils.GetCondaExecutablePath(version.PrefixPath, allowBatch: false);

            Assert.IsTrue(File.Exists(condaPath), $"Conda executable not found: '{condaPath}' for environment prefix at '{version.PrefixPath}'");
            return(CondaEnvironmentManager.Create(condaPath));
        }
Ejemplo n.º 3
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);
        }