def remove_files(files: Files) -> Files: to_remove = [] for file in files: if file.src_path in {'plugins.py', 'requirements.txt', 'cli_help.txt'}: to_remove.append(file) elif file.src_path.startswith('__pycache__/'): to_remove.append(file) logger.debug('removing files: %s', [f.src_path for f in to_remove]) for f in to_remove: files.remove(f) return files
def test_files_append_remove_src_paths(self): fs = [ File('index.md', '/path/to/docs', '/path/to/site', use_directory_urls=True), File('foo/bar.md', '/path/to/docs', '/path/to/site', use_directory_urls=True), File('foo/bar.html', '/path/to/docs', '/path/to/site', use_directory_urls=True), File('foo/bar.jpg', '/path/to/docs', '/path/to/site', use_directory_urls=True), File('foo/bar.js', '/path/to/docs', '/path/to/site', use_directory_urls=True), File('foo/bar.css', '/path/to/docs', '/path/to/site', use_directory_urls=True) ] files = Files(fs) self.assertEqual(len(files), 6) self.assertEqual(len(files.src_paths), 6) extra_file = File('extra.md', '/path/to/docs', '/path/to/site', use_directory_urls=True) self.assertFalse(extra_file.src_path in files) files.append(extra_file) self.assertEqual(len(files), 7) self.assertEqual(len(files.src_paths), 7) self.assertTrue(extra_file.src_path in files) files.remove(extra_file) self.assertEqual(len(files), 6) self.assertEqual(len(files.src_paths), 6) self.assertFalse(extra_file.src_path in files)