Skip to content

Commit

Permalink
Save output with LF line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
17451k committed Apr 15, 2020
1 parent d1c8e86 commit 0998a27
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions eventb_to_txt/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.

import io
import os


Expand Down Expand Up @@ -33,12 +34,15 @@ def _print_comment(self, data, f):
comment = comment.replace('\n', ' ')
f.write(comment)
else:
f.write(data['comment'])
comment = data['comment'].replace('\r\n', '\n')
f.write(comment)

f.write('\n')

def _trim_trailing_whitespaces(self, path):
def _post_process_file(self, path):
# trim trailing whitespaces
lines = ''.join([line.rstrip() + '\n' for line in open(path).readlines()])

with open(path, 'w') as f:
# save file with LF line endings
with io.open(path, 'w', newline='\n') as f:
f.writelines(lines)
2 changes: 1 addition & 1 deletion eventb_to_txt/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def to_txt(self, out_path, merge=False):

f.write('end\n')

self._trim_trailing_whitespaces(out_path)
self._post_process_file(out_path)

def __print_context_head(self, f):
f.write('context ' + self.get_component_name())
Expand Down
2 changes: 1 addition & 1 deletion eventb_to_txt/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def to_txt(self, out_path, merge=False):

f.write('end\n')

self._trim_trailing_whitespaces(out_path)
self._post_process_file(out_path)

def __print_machine_head(self, f):
f.write('machine ' + self.get_component_name())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='eventb-to-txt',
version='1.3.1',
version='1.3.2',
author='Ilya Shchepetkov',
author_email='ilya.shchepetkov@yandex.ru',
license='LICENSE.txt',
Expand Down

0 comments on commit 0998a27

Please sign in to comment.