Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Strip trailing whitespaces @ EOL when dumping FST
Browse files Browse the repository at this point in the history
It's a workaround for PyCQA/redbaron#190

Also:
* Ensure there's LF @ rewritten module EOL
  • Loading branch information
webknjaz committed Jan 16, 2020
1 parent 81b6bab commit 84383a9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def write_text_into_file(path, text):
return f.write(text)


def write_fst_into_file(path, fst):
"""Dump fst into the given file path."""
write_text_into_file(path, fst.dumps().rstrip() + '\n')


def render_fst(fst):
"""Render FST node in color when in terminal."""
node_txt = str(fst)
Expand Down Expand Up @@ -845,13 +850,13 @@ def fst_rewrite_session(src_path, dst_path):

yield mod_fst

new_mod_src_text = mod_fst.dumps()
new_mod_src_text = mod_fst.dumps().rstrip() + '\n'

if src_path == dst_path and mod_src_text == new_mod_src_text:
return

logger.info('Rewriting plugin references in %s', dst_path)
write_text_into_file(dst_path, new_mod_src_text)
write_fst_into_file(dst_path, mod_fst)


def read_module_txt_n_fst(path):
Expand Down

0 comments on commit 84383a9

Please sign in to comment.