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
  • Loading branch information
webknjaz committed Jan 7, 2020
1 parent 254dc36 commit 35d9f43
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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."""
Expand Down Expand Up @@ -733,12 +738,12 @@ def rewrite_py(src, dest, collection, spec, namespace, args):

rewrite_class_property(mod_fst, collection, namespace, dest)

plugin_data_new = mod_fst.dumps()
plugin_data_new = mod_fst.dumps().rstrip()

if mod_src_text != plugin_data_new:
logger.info('Rewriting plugin references in %s', dest)

write_text_into_file(dest, plugin_data_new)
write_fst_into_file(dest, mod_fst)

return (import_deps, docs_deps)

Expand Down Expand Up @@ -1367,7 +1372,7 @@ def rewrite_unit_tests(collection_dir, collection, spec, namespace, args):
_unit_test_module_src_text, unit_test_module_fst = read_module_txt_n_fst(file_path)
deps += rewrite_imports(unit_test_module_fst, collection, spec, namespace, args)
deps += rewrite_unit_tests_patch(unit_test_module_fst, collection, spec, namespace, args)
write_text_into_file(file_path, unit_test_module_fst.dumps())
write_fst_into_file(file_path, unit_test_module_fst)

return deps

Expand Down

0 comments on commit 35d9f43

Please sign in to comment.