def write(<EOL>contents: str,<EOL>path: Union[str, pathlib.Path],<EOL>verbose: bool = False,<EOL>logger_func=None,<EOL>) -> bool:
print_func = logger_func or print<EOL>path = pathlib.Path(path)<EOL>if path.exists():<EOL><INDENT>with path.open("<STR_LIT:r>") as file_pointer:<EOL><INDENT>old_contents = file_pointer.read()<EOL><DEDENT>if old_contents == contents:<EOL><INDENT>if verbose:<EOL><INDENT>print_func("<STR_LIT>".format(path))<EOL><DEDENT>return False<EOL><DEDENT>else:<EOL><INDENT>with path.open("<STR_LIT:w>") as file_pointer:<EOL><INDENT>file_pointer.write(contents)<EOL><DEDENT>if verbose:<EOL><INDENT>print_func("<STR_LIT>".format(path))<EOL><DEDENT>return True<EOL><DEDENT><DEDENT>elif not path.exists():<EOL><INDENT>if not path.parent.exists():<EOL><INDENT>path.parent.mkdir(parents=True)<EOL><DEDENT>with path.open("<STR_LIT:w>") as file_pointer:<EOL><INDENT>file_pointer.write(contents)<EOL><DEDENT>if verbose:<EOL><INDENT>print_func("<STR_LIT>".format(path))<EOL><DEDENT><DEDENT>return True<EOL>
Writes ``contents`` to ``path``.

Checks if ``path`` already exists and only write out new contents if the
old contents do not match.

Creates any intermediate missing directories.

:param contents: the file contents to write
:param path: the path to write to
:param verbose: whether to print output