Пример #1
0
        private static IEnumerable <InterpreterConfiguration> TestTriggerDiscovery(
            IVsFolderWorkspaceService workspaceService,
            Action triggerDiscovery,
            bool useDiscoveryStartedEvent = false
            )
        {
            using (var evt = new AutoResetEvent(false))
                using (var provider = new WorkspaceInterpreterFactoryProvider(workspaceService)) {
                    // This initializes the provider, discovers the initial set
                    // of factories and starts watching the filesystem.
                    var configs = provider.GetInterpreterConfigurations();

                    if (useDiscoveryStartedEvent)
                    {
                        provider.DiscoveryStarted += (sender, e) => {
                            evt.Set();
                        };
                    }
                    else
                    {
                        provider.InterpreterFactoriesChanged += (sender, e) => {
                            evt.Set();
                        };
                    }

                    triggerDiscovery();
                    Assert.IsTrue(evt.WaitOne(5000), "Failed to trigger discovery.");
                    return(provider.GetInterpreterConfigurations());
                }
        }
Пример #2
0
        private static IEnumerable <InterpreterConfiguration> TestTriggerDiscovery(
            IPythonWorkspaceContext workspaceContext,
            Action triggerDiscovery,
            IPythonWorkspaceContextProvider workspaceContextProvider = null,
            bool useDiscoveryStartedEvent = false
            )
        {
            workspaceContextProvider = workspaceContextProvider
                                       ?? new WorkspaceTestHelper.MockWorkspaceContextProvider(workspaceContext);

            using (var provider = new WorkspaceInterpreterFactoryProvider(workspaceContextProvider))
                using (var evt = new AutoResetEvent(false)) {
                    // This initializes the provider, discovers the initial set
                    // of factories and starts watching the filesystem.
                    provider.GetInterpreterFactories();

                    if (useDiscoveryStartedEvent)
                    {
                        provider.DiscoveryStarted += (sender, e) => {
                            evt.Set();
                        };
                    }
                    else
                    {
                        provider.InterpreterFactoriesChanged += (sender, e) => {
                            evt.Set();
                        };
                    }

                    triggerDiscovery();
                    Assert.IsTrue(evt.WaitOne(5000), "Failed to trigger discovery.");
                    return(provider.GetInterpreterConfigurations());
                }
        }
Пример #3
0
        public void DetectLocalEnvOutsideWorkspace()
        {
            var python = PythonPaths.Python37_x64 ?? PythonPaths.Python37;

            var tempFolder      = TestData.GetTempPath();
            var workspaceFolder = Path.Combine(tempFolder, "workspace");
            var envFolder       = Path.Combine(tempFolder, "outside");

            Directory.CreateDirectory(workspaceFolder);
            File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty);

            // Create virtual env outside the workspace folder
            using (var p = ProcessOutput.RunHiddenAndCapture(python.InterpreterPath, "-m", "venv", envFolder)) {
                Console.WriteLine(p.Arguments);
                p.Wait();
                Console.WriteLine(string.Join(Environment.NewLine, p.StandardOutputLines.Concat(p.StandardErrorLines)));
                Assert.AreEqual(0, p.ExitCode);
            }

            // Normally a local virtual environment outside the workspace
            // wouldn't be detected, but it is when it's referenced from
            // the workspace python settings.
            var aggregatedSettings = new MockWorkspaceSettings(
                new Dictionary <string, string> {
                { "Interpreter", @"..\outside\scripts\python.exe" }
            }
                );
            var settingsManager  = new MockWorkspaceSettingsManager(aggregatedSettings);
            var workspace        = new MockWorkspace(workspaceFolder, settingsManager);
            var workspaceService = new MockWorkspaceService(workspace);

            using (var provider = new WorkspaceInterpreterFactoryProvider(workspaceService)) {
                var configs = provider.GetInterpreterConfigurations().ToArray();

                Assert.AreEqual(1, configs.Length);
                Assert.IsTrue(PathUtils.IsSamePath(
                                  Path.Combine(envFolder, "scripts", "python.exe"),
                                  configs[0].InterpreterPath
                                  ));
                Assert.AreEqual("Workspace|Workspace|outside", configs[0].Id);
            }
        }