def is_declaring_file(address, file_path): # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. # # We could call into the engine to ask for the file that declared the address. return (os.path.dirname(file_path) == address.spec_path and BuildFile._is_buildfile_name(os.path.basename(file_path)))
def is_declaring_file(address, file_path): # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. # # We could call into the engine to ask for the file that declared the address. return (os.path.dirname(file_path) == address.spec_path and BuildFile._is_buildfile_name(os.path.basename(file_path)))
def any_is_declaring_file(address, file_paths): try: # A precise check for BuildFileAddress return address.rel_path in file_paths except AttributeError: pass # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. return any(address.spec_path == os.path.dirname(fp) for fp in file_paths if BuildFile._is_buildfile_name(os.path.basename(fp)))
def any_is_declaring_file(address, file_paths): try: # A precise check for BuildFileAddress return address.rel_path in file_paths except AttributeError: pass # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. return any(address.spec_path == os.path.dirname(fp) for fp in file_paths if BuildFile._is_buildfile_name(os.path.basename(fp)))
def is_declaring_file(address, file_path): if not BuildFile._is_buildfile_name(os.path.basename(file_path)): return False try: # A precise check for BuildFileAddress return address.rel_path == file_path except AttributeError: # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. # # TODO: remove this after https://github.com/pantsbuild/pants/issues/3925 lands return os.path.dirname(file_path) == address.spec_path
def is_declaring_file(address, file_path): if not BuildFile._is_buildfile_name(os.path.basename(file_path)): return False try: # A precise check for BuildFileAddress return address.rel_path == file_path except AttributeError: # NB: this will cause any BUILD file, whether it contains the address declaration or not to be # considered the one that declared it. That's ok though, because the spec path should be enough # information for debugging most of the time. # # TODO: remove this after https://github.com/pantsbuild/pants/issues/3925 lands return os.path.dirname(file_path) == address.spec_path
def source_clone(self, source_dir): with self.temporary_sourcedir() as clone_dir: target_spec_dir = os.path.relpath(clone_dir) for dir_path, dir_names, file_names in os.walk(source_dir): clone_dir_path = os.path.join(clone_dir, os.path.relpath(dir_path, source_dir)) for dir_name in dir_names: os.mkdir(os.path.join(clone_dir_path, dir_name)) for file_name in file_names: with open(os.path.join(dir_path, file_name), 'r') as f: content = f.read() if BuildFile._is_buildfile_name(file_name): content = content.replace(source_dir, target_spec_dir) with open(os.path.join(clone_dir_path, file_name), 'w') as f: f.write(content) yield clone_dir
def source_clone(self, source_dir): with self.temporary_sourcedir() as clone_dir: target_spec_dir = os.path.relpath(clone_dir) for dir_path, dir_names, file_names in os.walk(source_dir): clone_dir_path = os.path.join(clone_dir, os.path.relpath(dir_path, source_dir)) for dir_name in dir_names: os.mkdir(os.path.join(clone_dir_path, dir_name)) for file_name in file_names: with open(os.path.join(dir_path, file_name), 'r') as f: content = f.read() if BuildFile._is_buildfile_name(file_name): content = content.replace(source_dir, target_spec_dir) with open(os.path.join(clone_dir_path, file_name), 'w') as f: f.write(content) yield clone_dir