Exemplo n.º 1
0
        public void FactoryProvider()
        {
            var provider  = new CPythonInterpreterFactoryProvider(null, false);
            var factories = provider.GetInterpreterFactories().ToArray();

            Console.WriteLine("Discovered:");
            foreach (var factory in factories)
            {
                var id = factory.Configuration.Id;
                Console.WriteLine("  {0} - {1}".FormatInvariant(id, factory.Configuration.Description));

                Assert.IsTrue(id.StartsWith("Global|"), "Expected 'Global' prefix on '{0}'".FormatInvariant(factory.Configuration.Id));

                if (id.StartsWith("Global|PythonCore|"))
                {
                    var description = factory.Configuration.Description;
                    var sysVersion  = factory.Configuration.Version;
                    var sysArch     = factory.Configuration.Architecture;

                    Assert.IsTrue(sysVersion.Major == 2 || sysVersion.Major == 3, "unknown SysVersion '{0}'".FormatInvariant(sysVersion));

                    Assert.AreEqual(PythonRegistrySearch.PythonCoreCompanyDisplayName, provider.GetProperty(id, PythonRegistrySearch.CompanyPropertyKey));
                    Assert.AreEqual(PythonRegistrySearch.PythonCoreSupportUrl, provider.GetProperty(id, PythonRegistrySearch.SupportUrlPropertyKey));
                }
            }
        }
Exemplo n.º 2
0
        public void FactoryProvider()
        {
            var provider  = new CPythonInterpreterFactoryProvider(null, false);
            var factories = provider.GetInterpreterFactories().ToArray();

            Console.WriteLine("Discovered:");
            foreach (var factory in factories)
            {
                var id = factory.Configuration.Id;
                Console.WriteLine("  {0} - {1}".FormatInvariant(id, factory.Configuration.Description));


                Assert.IsTrue(id.StartsWith("Global|"), "Expected 'Global' prefix on '{0}'".FormatInvariant(factory.Configuration.Id));

                Assert.IsNotNull(factory.CreateInterpreter(), "failed to create interpreter");

                if (id.StartsWith("Global|PythonCore|"))
                {
                    var description = factory.Configuration.Description;
                    var sysVersion  = factory.Configuration.Version;
                    var sysArch     = factory.Configuration.Architecture;

                    // Tests are not yet using a regular install of 3.7
                    if (sysVersion != new Version(3, 7))
                    {
                        AssertUtil.Contains(description, "Python", sysVersion.ToString(), sysArch.ToString());
                    }

                    Assert.IsTrue(sysVersion.Major == 2 || sysVersion.Major == 3, "unknown SysVersion '{0}'".FormatInvariant(sysVersion));

                    Assert.AreEqual(PythonRegistrySearch.PythonCoreCompanyDisplayName, provider.GetProperty(id, PythonRegistrySearch.CompanyPropertyKey));
                    Assert.AreEqual(PythonRegistrySearch.PythonCoreSupportUrl, provider.GetProperty(id, PythonRegistrySearch.SupportUrlPropertyKey));
                }
            }
        }
        private async Task <AddExistingEnvironmentView> AutoDetectAsync(AddExistingEnvironmentView view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort without changes.
                return(view);
            }

            if (string.IsNullOrEmpty(view.Description))
            {
                view.Description = PathUtils.GetFileOrDirectoryName(view.PrefixPath);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1])); print(sys.platform)"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(view.InterpreterPath);
                if (arch != InterpreterArchitecture.Unknown)
                {
                    view.ArchitectureName = arch.ToString();
                }

                if (string.IsNullOrEmpty(view.PathEnvironmentVariable))
                {
                    view.PathEnvironmentVariable = "PYTHONPATH";
                }
            }

            return(view);
        }
Exemplo n.º 4
0
        public void FactoryProvider()
        {
            var provider  = new CPythonInterpreterFactoryProvider();
            var factories = provider.GetInterpreterFactories().ToArray();

            if (factories.Length > 0)
            {
                Assert.IsTrue(factories[0].Description == "Python");
                Assert.IsTrue(factories[0].Configuration.Version.Major == 2 || factories[0].Configuration.Version.Major == 3);
                Assert.IsTrue(factories[0].Id == new Guid("{2AF0F10D-7135-4994-9156-5D01C9C11B7E}"));
                Assert.IsTrue(factories[0].CreateInterpreter() != null);
            }
        }
Exemplo n.º 5
0
 private static void TestTriggerDiscovery(string userProfileFolder, Action triggerDiscovery)
 {
     using (var evt = new AutoResetEvent(false))
         using (var globalProvider = new CPythonInterpreterFactoryProvider(null, false))
             using (var condaProvider = new CondaEnvironmentFactoryProvider(globalProvider, null, new JoinableTaskFactory(new JoinableTaskContext()), true, userProfileFolder)) {
                 // This initializes the provider, discovers the initial set
                 // of factories and starts watching the filesystem.
                 var configs = condaProvider.GetInterpreterConfigurations();
                 condaProvider.DiscoveryStarted += (sender, e) => {
                     evt.Set();
                 };
                 triggerDiscovery();
                 Assert.IsTrue(evt.WaitOne(5000), "Failed to trigger discovery.");
             }
 }
Exemplo n.º 6
0
        private static IPythonInterpreterFactory TryFindFactory(string idOrDescription)
        {
            var provider = new CPythonInterpreterFactoryProvider(null, watchRegistry: false);
            var factory  = provider.GetInterpreterFactory(idOrDescription);

            if (factory == null)
            {
                var config = provider.GetInterpreterConfigurations().FirstOrDefault(c => idOrDescription.Equals(c.Description, StringComparison.OrdinalIgnoreCase));
                if (config != null)
                {
                    factory = provider.GetInterpreterFactory(config.Id);
                }
            }
            if (factory == null)
            {
                Assert.Inconclusive("Requested interpreter '{0}' is not installed", idOrDescription);
                return(null);
            }

            return(factory);
        }
Exemplo n.º 7
0
        private async Task <ConfigurationValues> AutoDetectAsync(ConfigurationValues view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                if (File.Exists(view.InterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.InterpreterPath);
                }
                else if (File.Exists(view.WindowsInterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.WindowsInterpreterPath);
                }
                else
                {
                    // Don't have enough information, so abort without changing
                    // any settings.
                    return(view);
                }
                while (Directory.Exists(view.PrefixPath) && !File.Exists(PathUtils.FindFile(view.PrefixPath, "site.py")))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.PrefixPath);
                }
            }

            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort withou changing any settings.
                return(view);
            }

            if (string.IsNullOrEmpty(view.Description))
            {
                view.Description = PathUtils.GetFileOrDirectoryName(view.PrefixPath);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }
            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(view.InterpreterPath);
                if (arch != InterpreterArchitecture.Unknown)
                {
                    view.ArchitectureName = arch.ToString();
                }
            }

            return(view);
        }