Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vsProject"></param>
        /// <returns>True if loaded any files</returns>
        private bool LoadProject(IVsProject vsProject)
        {
            // check for python projects
            var pyProj = PythonProject.FromObject(vsProject);

            if (pyProj == null)
            {
                return(false);
            }

            // always register for project property changes
            pyProj.ProjectPropertyChanged -= OnTestPropertiesChanged;
            pyProj.ProjectPropertyChanged += OnTestPropertiesChanged;

            TestFrameworkType testFrameworkType = GetTestFramework(pyProj);

            if (testFrameworkType == TestFrameworkType.None)
            {
                return(false);
            }

            pyProj.ActiveInterpreterChanged -= OnActiveInterpreterChanged;
            pyProj.ActiveInterpreterChanged += OnActiveInterpreterChanged;
            _packageManagerEventSink.WatchPackageManagers(pyProj.GetInterpreterFactory());

            var projInfo = new ProjectInfo(pyProj);
            var files    = FilteredTestOrSettingsFiles(vsProject);

            UpdateContainersAndListeners(files, projInfo, isAdd: true);
            _projectMap[projInfo.ProjectHome] = projInfo;
            return(files.Any());
        }
        private void SetupWorkspace(IPythonWorkspaceContext workspace)
        {
            if (workspace == null)
            {
                return;
            }

            TestFrameworkType testFrameworkType = GetTestFramework(workspace);

            if (testFrameworkType != TestFrameworkType.None)
            {
                var projInfo = new ProjectInfo(workspace);
                _projectMap[projInfo.ProjectHome] = projInfo;

                var oldWatcher = _testFilesUpdateWatcher;
                _testFilesUpdateWatcher = new TestFilesUpdateWatcher();
                _testFilesUpdateWatcher.FileChangedEvent += OnWorkspaceFileChanged;
                _testFilesUpdateWatcher.AddDirectoryWatch(workspace.Location);
                oldWatcher?.Dispose();

                Regex testFileFilterRegex         = new Regex(@".*\.(py|txt)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                Predicate <string> testFileFilter = (x) => testFileFilterRegex.IsMatch(x);
                foreach (var file in _workspaceContextProvider.Workspace.EnumerateUserFiles(testFileFilter))
                {
                    projInfo.AddTestContainer(this, file);
                }

                workspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged;
                workspace.ActiveInterpreterChanged += OnActiveInterpreterChanged;
                _packageManagerEventSink.WatchPackageManagers(workspace.CurrentFactory);
            }
        }
        private void SetupWorkspace(IPythonWorkspaceContext workspace)
        {
            if (workspace == null ||
                GetTestFramework(workspace) == TestFrameworkType.None)
            {
                return;
            }

            try {
                Predicate <string> testFileFilter = (x) => PythonConstants.TestFileExtensionRegex.IsMatch(PathUtils.GetFileOrDirectoryName(x));

                var projInfo = new ProjectInfo(workspace);
                foreach (var file in _workspaceContextProvider.Workspace.EnumerateUserFiles(testFileFilter))
                {
                    projInfo.AddTestContainer(this, file);
                }

                _projectMap[projInfo.ProjectHome] = projInfo;
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                Trace.WriteLine("Exception : " + ex.Message);
            }

            // Register listeners
            var oldWatcher = _testFilesUpdateWatcher;

            _testFilesUpdateWatcher = new TestFilesUpdateWatcher();
            _testFilesUpdateWatcher.FileChangedEvent += OnWorkspaceFileChanged;
            _testFilesUpdateWatcher.AddDirectoryWatch(workspace.Location);
            oldWatcher?.Dispose();

            workspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged;
            workspace.ActiveInterpreterChanged += OnActiveInterpreterChanged;
            _packageManagerEventSink.WatchPackageManagers(workspace.CurrentFactory);
        }