Skip to content

Commit f1804ba

Browse files
authored
Merge pull request #136 from IDEMSInternational/fix/windows-linebreak-and-utf8-encoding
Fix Windows linebreaks for table export and force utf-8 encoding
2 parents 23dfb4a + c0febb6 commit f1804ba

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/rpft/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_flows(args):
2121
tags=args.tags,
2222
)
2323

24-
with open(args.output, "w") as export:
24+
with open(args.output, "w", encoding="utf-8") as export:
2525
json.dump(flows, export, indent=4)
2626

2727

src/rpft/converters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create_flows(input_files, output_file, sheet_format, data_models=None, tags=
3737
flows = parser.parse_all().render()
3838

3939
if output_file:
40-
with open(output_file, "w") as export:
40+
with open(output_file, "w", encoding='utf8') as export:
4141
json.dump(flows, export, indent=4)
4242

4343
return flows
@@ -70,7 +70,7 @@ def flows_to_sheets(
7070
:param numbered: Use sequential numbers instead of short reps for row IDs.
7171
:returns: None.
7272
"""
73-
with open(input_file, "r") as f:
73+
with open(input_file, "r", encoding='utf-8') as f:
7474
data = json.load(f)
7575
container = RapidProContainer.from_dict(data)
7676
for flow in container.flows:

src/rpft/parsers/common/rowdatasheet.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ def export(self, filename, file_format="csv"):
3838
"""
3939
data = self.convert_to_tablib()
4040
exported_data = data.export(file_format)
41-
write_type = "w" if type(exported_data) is str else "wb"
42-
with open(filename, write_type) as f:
41+
if type(exported_data) is str:
42+
# There is a strange bug where on Windows, csv files would get
43+
# exported with \r\r\n linebreaks. The below fixes this.
44+
exported_data = exported_data.replace("\r", "")
45+
exported_data = exported_data.encode("utf-8")
46+
with open(filename, "wb") as f:
4347
f.write(exported_data)
4448

4549
def convert_to_tablib(self):

0 commit comments

Comments
 (0)