Skip to content

Commit

Permalink
fix end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoMF committed Aug 22, 2023
1 parent b94dbd2 commit 77e791f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gepetuto/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def generate_from_id(tp_id: int):
generate_ipynb(ipynb, folder)


def fix_end_of_content(content):
"""Remove extra lines."""
while 1:
if content[-1] == "\n":
content.pop()
else:
return content
return None


def generate_ipynb(ipynb, folder, force_load=False): # noqa: C901
"""Cut python files in bits loadable by ipython."""
LOG.info("processing '%s' with scripts in '%s'", ipynb, folder)
Expand Down Expand Up @@ -57,6 +67,7 @@ def generate_ipynb(ipynb, folder, force_load=False): # noqa: C901
f"at line {line_number + 1}"
)
raise SyntaxError(msg)
content = fix_end_of_content(content)
with dest.open("w") as f_out:
f_out.write("".join(content))
for cell_number, cell in enumerate(cells_copy):
Expand Down Expand Up @@ -87,4 +98,5 @@ def generate_ipynb(ipynb, folder, force_load=False): # noqa: C901
elif dest is not None:
content.append(line)
with ipynb.open("w") as f:
f.write(json.dumps(data, indent=1))
json.dump(data, f)
f.write("\n")

0 comments on commit 77e791f

Please sign in to comment.