From b4d5f51f7be9b5a0f6dc9eed5d99f2de8695af56 Mon Sep 17 00:00:00 2001 From: Chris Mackey Date: Tue, 4 Nov 2025 16:04:56 -0800 Subject: [PATCH] fix(commandutil): Ensure output is always encoded to utf-8 --- ladybug/commandutil.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ladybug/commandutil.py b/ladybug/commandutil.py index 4fea015e..cfba6a6b 100644 --- a/ladybug/commandutil.py +++ b/ladybug/commandutil.py @@ -1,5 +1,6 @@ # coding=utf-8 """Utility functions for running the functions of CLI commands outside of the CLI.""" +import sys import os @@ -49,11 +50,20 @@ def process_content_to_output(content_str, output_file=None): dir_name = os.path.dirname(os.path.abspath(output_file)) if not os.path.isdir(dir_name): os.makedirs(dir_name) - with open(output_file, 'w') as of: - of.write(content_str) + if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8 + with open(output_file, 'w') as of: + of.write(content_str.encode('utf-8')) + else: + with open(output_file, 'w', encoding='utf-8') as of: + of.write(content_str) else: if 'stdout' not in str(output_file): dir_name = os.path.dirname(os.path.abspath(output_file.name)) if not os.path.isdir(dir_name): os.makedirs(dir_name) - output_file.write(content_str) + if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8 + with open(output_file, 'w') as of: + of.write(content_str.encode('utf-8')) + else: + with open(output_file, 'w', encoding='utf-8') as of: + of.write(content_str)