in src/epam/auto_llm_eval/evaluator.py [0:0]
def write_file(file_path: str, content: str) -> None:
"""
Write the content to a file.
This function opens the specified file in write mode and writes the given
content to it. It first converts the file path to absolute and checks that
the parent directory exists.
It uses UTF-8 encoding to handle various character sets.
Args:
file_path (str): The path to the file where the content will be
written.
content (str): The content to be written to the file.
Raises:
IOError: If there's an error writing to the file.
FileNotFoundError: If the parent directory does not exist.
"""
abs_path = os.path.abspath(os.path.expanduser(file_path))
parent_dir = os.path.dirname(abs_path)
if not os.path.exists(parent_dir):
raise FileNotFoundError(
f"Parent directory does not exist: {parent_dir}"
)
with open(abs_path, "w", encoding="utf-8") as f:
f.write(content)