def classify_source_files( paths: Iterable[str]) -> dict[type[Target], set[str]]: """Returns a dict of target type -> files that belong to targets of that type.""" tests_filespec = Filespec( includes=list(PythonTestsGeneratingSourcesField.default)) test_utils_filespec = Filespec( includes=list(PythonTestUtilsGeneratingSourcesField.default)) path_to_file_name = {path: os.path.basename(path) for path in paths} test_file_names = set( matches_filespec(tests_filespec, paths=path_to_file_name.values())) test_util_file_names = set( matches_filespec(test_utils_filespec, paths=path_to_file_name.values())) test_files = { path for path, file_name in path_to_file_name.items() if file_name in test_file_names } test_util_files = { path for path, file_name in path_to_file_name.items() if file_name in test_util_file_names } library_files = set(paths) - test_files - test_util_files return { PythonTestsGeneratorTarget: test_files, PythonTestUtilsGeneratorTarget: test_util_files, PythonSourcesGeneratorTarget: library_files, }
def classify_source_files( paths: Iterable[str]) -> dict[type[Target], set[str]]: """Returns a dict of target type -> files that belong to targets of that type.""" scalatest_filespec = Filespec( includes=list(ScalatestTestsGeneratorSourcesField.default)) junit_filespec = Filespec( includes=list(ScalaJunitTestsGeneratorSourcesField.default)) scalatest_files = { path for path in paths if os.path.basename(path) in set( matches_filespec(scalatest_filespec, paths=[os.path.basename(path) for path in paths])) } junit_files = { path for path in paths if os.path.basename(path) in set( matches_filespec(junit_filespec, paths=[os.path.basename(path) for path in paths])) } sources_files = set(paths) - scalatest_files - junit_files return { ScalaJunitTestsGeneratorTarget: junit_files, ScalaSourcesGeneratorTarget: sources_files, ScalatestTestsGeneratorTarget: scalatest_files, }
async def find_fortran_targets( req: PutativeFortranTargetsRequest, all_owned_sources: AllOwnedSources) -> PutativeTargets: all_fortran_files = await Get(Paths, PathGlobs, req.path_globs("*.f90")) unowned_shell_files = set(all_fortran_files.files) - set(all_owned_sources) tests_filespec = Filespec(includes=list(FortranTestsSources.default)) test_filenames = set( matches_filespec( tests_filespec, paths=[os.path.basename(path) for path in unowned_shell_files])) test_files = { path for path in unowned_shell_files if os.path.basename(path) in test_filenames } sources_files = set(unowned_shell_files) - test_files classified_unowned_shell_files = { FortranTestsTarget: test_files, FortranLibraryTarget: sources_files, } pts = [] for tgt_type, paths in classified_unowned_shell_files.items(): for dirname, filenames in group_by_dir(paths).items(): name = "tests" if tgt_type == FortranTestsTarget else None pts.append( PutativeTarget.for_target_type( tgt_type, path=dirname, name=name, triggering_sources=sorted(filenames))) return PutativeTargets(pts)
def classify_source_files(paths: Iterable[str]) -> dict[type[Target], set[str]]: """Returns a dict of target type -> files that belong to targets of that type.""" tests_filespec = Filespec(includes=list(Shunit2TestsGeneratorSourcesField.default)) test_filenames = set( matches_filespec(tests_filespec, paths=[os.path.basename(path) for path in paths]) ) test_files = {path for path in paths if os.path.basename(path) in test_filenames} sources_files = set(paths) - test_files return {Shunit2TestsGeneratorTarget: test_files, ShellSourcesGeneratorTarget: sources_files}
def validate_build_file_name(self, build_file_patterns: tuple[str, ...]) -> None: """Check that the specified BUILD file name works with the repository's BUILD file patterns.""" filespec = Filespec(includes=list(build_file_patterns)) if not bool(matches_filespec(filespec, paths=[self.build_file_name])): raise ValueError( f"The option `[{self.options_scope}].build_file_name` is set to " f"`{self.build_file_name}`, which is not compatible with " f"`[GLOBAL].build_patterns`: {sorted(build_file_patterns)}. This means that " "generated BUILD files would be ignored.\n\n" "To fix, please update the options so that they are compatible." )
def classify_source_files( paths: Iterable[str]) -> dict[type[Target], set[str]]: """Returns a dict of target type -> files that belong to targets of that type.""" tests_filespec = Filespec(includes=list(PythonTestsSources.default)) test_filenames = set( matches_filespec(tests_filespec, paths=[os.path.basename(path) for path in paths])) test_files = { path for path in paths if os.path.basename(path) in test_filenames } library_files = set(paths) - test_files return {PythonTests: test_files, PythonLibrary: library_files}
def filter_by_ignores( self, putative_targets: Iterable[PutativeTarget], build_file_ignores: tuple[str, ...]) -> Iterator[PutativeTarget]: ignore_paths_filespec = Filespec( includes=[*self.ignore_paths, *build_file_ignores]) for ptgt in putative_targets: is_ignored_file = bool( matches_filespec( ignore_paths_filespec, paths=[os.path.join(ptgt.path, self.build_file_name)], )) if is_ignored_file: continue # Note that `tailor` can only generate explicit targets, so we don't need to # worry about generated address syntax (`#`) or file address syntax. address = f"{ptgt.path or '//'}:{ptgt.name}" if address in self.ignore_adding_targets: continue yield ptgt