From ed0752943d90e18c41af130ea9b9a74ab4da9505 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 25 Sep 2019 23:24:44 +0200 Subject: [PATCH] Strip trailing whitespaces @ EOL when dumping FST It's a workaround for https://github.com/PyCQA/redbaron/issues/190 --- migrate.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migrate.py b/migrate.py index 3a43c221..a664dbff 100755 --- a/migrate.py +++ b/migrate.py @@ -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()) + + @contextlib.contextmanager def working_directory(target_dir): """Temporary change dir to the target and change back on exit.""" @@ -788,13 +793,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() 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):