Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix write_file to use a single operation #3359

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,21 @@ def render_template(template, **kwargs):
return t.render(kwargs)


def write_file(filename: str, content: str):
def write_file(filename: str, content: str, header: Optional[str] = None) -> None:
"""
Write a file with the given filename and content and returns None.

:param filename: A string containing the target filename.
:param content: A string containing the data to be written.
:param header: A header, if None it will use default header.
:return: None
"""
if header is None:
content = MOLECULE_HEADER + "\n\n" + content

with open_file(filename, "w") as f:
f.write(content)

file_prepender(filename)


def molecule_prepender(content: str) -> str:
"""Return molecule identification header."""
Expand Down