def visit_variants(self, func, variants=None, **kwargs):
if variants:<EOL><INDENT>present_variants = list(range(self.package.num_variants))<EOL>invalid_variants = set(variants) - set(present_variants)<EOL>if invalid_variants:<EOL><INDENT>raise BuildError(<EOL>"<STR_LIT>"<EOL>% "<STR_LIT:U+002CU+0020>".join(str(x) for x in sorted(invalid_variants)))<EOL><DEDENT><DEDENT>results = []<EOL>num_visited = <NUM_LIT:0><EOL>for variant in self.package.iter_variants():<EOL><INDENT>if variants and variant.index not in variants:<EOL><INDENT>self._print_header(<EOL>"<STR_LIT>"<EOL>% (variant.index, self._n_of_m(variant)))<EOL>continue<EOL><DEDENT>result = func(variant, **kwargs)<EOL>results.append(result)<EOL>num_visited += <NUM_LIT:1><EOL><DEDENT>return num_visited, results<EOL>
Iterate over variants and call a function on each.