@@ -479,7 +479,7 @@ def default_build_triple(verbose):
479479@contextlib .contextmanager
480480def output (filepath ):
481481 tmp = filepath + ".tmp"
482- with open (tmp , "w" ) as f :
482+ with open (tmp , "w" , encoding = "utf-8" ) as f :
483483 yield f
484484 try :
485485 if os .path .exists (filepath ):
@@ -778,7 +778,7 @@ def get_answer():
778778 # Use `/etc/os-release` instead of `/etc/NIXOS`.
779779 # The latter one does not exist on NixOS when using tmpfs as root.
780780 try :
781- with open ("/etc/os-release" , "r" ) as f :
781+ with open ("/etc/os-release" , "r" , encoding = "utf-8" ) as f :
782782 is_nixos = any (
783783 ln .strip () in ("ID=nixos" , "ID='nixos'" , 'ID="nixos"' )
784784 for ln in f
@@ -863,7 +863,8 @@ def fix_bin_or_dylib(self, fname):
863863 if ".so" not in fname :
864864 # Finally, set the correct .interp for binaries
865865 with open (
866- "{}/nix-support/dynamic-linker" .format (nix_deps_dir )
866+ "{}/nix-support/dynamic-linker" .format (nix_deps_dir ),
867+ encoding = "utf-8" ,
867868 ) as dynamic_linker :
868869 patchelf_args += ["--set-interpreter" , dynamic_linker .read ().rstrip ()]
869870
@@ -888,7 +889,7 @@ def program_out_of_date(self, stamp_path, key):
888889 """Check if the given program stamp is out of date"""
889890 if not os .path .exists (stamp_path ) or self .clean :
890891 return True
891- with open (stamp_path , "r" ) as stamp :
892+ with open (stamp_path , "r" , encoding = "utf-8" ) as stamp :
892893 return key != stamp .read ()
893894
894895 def bin_root (self ):
@@ -1276,7 +1277,7 @@ def parse_args(args):
12761277
12771278def parse_stage0_file (path ):
12781279 result = {}
1279- with open (path , "r" ) as file :
1280+ with open (path , "r" , encoding = "utf-8" ) as file :
12801281 for line in file :
12811282 line = line .strip ()
12821283 if line and not line .startswith ("#" ):
@@ -1346,7 +1347,7 @@ def bootstrap(args):
13461347
13471348 # HACK: This works because `self.get_toml()` returns the first match it finds for a
13481349 # specific key, so appending our defaults at the end allows the user to override them
1349- with open (include_path ) as included_toml :
1350+ with open (include_path , encoding = "utf-8" ) as included_toml :
13501351 config_toml += os .linesep + included_toml .read ()
13511352
13521353 # Configure initial bootstrap
@@ -1384,7 +1385,9 @@ def main():
13841385 if len (sys .argv ) == 1 or sys .argv [1 ] in ["-h" , "--help" ]:
13851386 try :
13861387 with open (
1387- os .path .join (os .path .dirname (__file__ ), "../etc/xhelp" ), "r"
1388+ os .path .join (os .path .dirname (__file__ ), "../etc/xhelp" ),
1389+ "r" ,
1390+ encoding = "utf-8" ,
13881391 ) as f :
13891392 # The file from bootstrap func already has newline.
13901393 print (f .read (), end = "" )
0 commit comments