def _load_raw_file_and_config( fname: str, root_config: FluffConfig) -> Tuple[str, FluffConfig, str]: """Load a raw file and the associated config.""" file_config = root_config.make_child_from_path(fname) encoding = get_encoding(fname=fname, config=file_config) # Check file size before loading. limit = file_config.get("large_file_skip_byte_limit") if limit: # Get the file size file_size = os.path.getsize(fname) if file_size > limit: raise SQLFluffSkipFile( f"Length of file {fname!r} is {file_size} bytes which is over " f"the limit of {limit} bytes. Skipping to avoid parser lock. " "Users can increase this limit in their config by setting the " "'large_file_skip_byte_limit' value, or disable by setting it " "to zero.") with open(fname, encoding=encoding, errors="backslashreplace") as target_file: raw_file = target_file.read() # Scan the raw file for config commands. file_config.process_raw_file_for_config(raw_file) # Return the raw file and config return raw_file, file_config, encoding
def test__parser__helper_get_encoding(fname, config_encoding, result): """Test get_encoding.""" assert (get_encoding( fname=fname, config=FluffConfig(overrides={ "encoding": config_encoding, "dialect": "ansi" }), ) == result)
def _load_raw_file_and_config(fname, root_config): """Load a raw file and the associated config.""" file_config = root_config.make_child_from_path(fname) encoding = get_encoding(fname=fname, config=file_config) with open(fname, encoding=encoding, errors="backslashreplace") as target_file: raw_file = target_file.read() # Scan the raw file for config commands. file_config.process_raw_file_for_config(raw_file) # Return the raw file and config return raw_file, file_config, encoding