def load_source_file(path: FilePath, parse_file_type: ParseFileType, project_name: str) -> SourceFile: file_contents = load_file_contents(path.absolute_path, strip=False) checksum = FileHash.from_contents(file_contents) source_file = SourceFile(path=path, checksum=checksum, parse_file_type=parse_file_type, project_name=project_name) source_file.contents = file_contents.strip() return source_file
def use_models(self, models): for k, v in models.items(): path = FilePath( searched_path='models', project_root=os.path.normcase(os.getcwd()), relative_path='{}.sql'.format(k), ) # FileHash can't be empty or 'search_key' will be None source_file = SourceFile(path=path, checksum=FileHash.from_contents('abc')) source_file.contents = v self.mock_models.append(source_file)
def load_file( self, path: FilePath, *, set_contents: bool = True, ) -> SourceFile: file_contents = load_file_contents(path.absolute_path, strip=False) checksum = FileHash.from_contents(file_contents) source_file = SourceFile(path=path, checksum=checksum) if set_contents: source_file.contents = file_contents.strip() else: source_file.contents = '' return source_file
def file_block_for(self, data: str, filename: str, searched: str): root_dir = get_abs_os_path('./dbt_modules/snowplow') filename = normalize(filename) path = FilePath( searched_path=searched, relative_path=filename, project_root=root_dir, ) source_file = SourceFile( path=path, checksum=FileHash.from_contents(data), ) source_file.contents = data return FileBlock(file=source_file)
def load_file(self, match: FilePath, *, set_contents: bool = False) -> SourceFile: if match.seed_too_large(): # We don't want to calculate a hash of this file. Use the path. return SourceFile.big_seed(match) else: # We want to calculate a hash, but we don't need the contents return super().load_file(match, set_contents=set_contents)
def _new_file(self, searched, name, match): if match: checksum = MatchingHash() else: checksum = MismatchedHash() path = FilePath( searched_path=normalize(searched), relative_path=normalize(name), project_root=normalize(self.root_project_config.project_root), ) return SourceFile(path=path, checksum=checksum)
def load_seed_source_file(match: FilePath, project_name) -> SourceFile: if match.seed_too_large(): # We don't want to calculate a hash of this file. Use the path. source_file = SourceFile.big_seed(match) else: file_contents = load_file_contents(match.absolute_path, strip=False) checksum = FileHash.from_contents(file_contents) source_file = SourceFile(path=match, checksum=checksum) source_file.contents = '' source_file.parse_file_type = ParseFileType.Seed source_file.project_name = project_name return source_file