summary refs log tree commit diff
path: root/pkgs/development/libraries/science/math/fenics/unicode.patch
blob: 2ef2709263ab47382c225b7b2d0cc397dc8fc679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From 0cc9e68de1181d950d4185bf3a87b69a87e4358f Mon Sep 17 00:00:00 2001
From: "James D. Trotter" <james@simula.no>
Date: Mon, 14 Aug 2017 16:43:53 +0200
Subject: [PATCH] Use a UTF-8 encoding to avoid errors with decoding non-ascii
 characters

---
 cmake/scripts/generate-swig-interface.py |  6 +++---
 utils/pylit/pylit.py                     | 10 +++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/cmake/scripts/generate-swig-interface.py b/cmake/scripts/generate-swig-interface.py
index 843a49229..7b85453d0 100644
--- a/cmake/scripts/generate-swig-interface.py
+++ b/cmake/scripts/generate-swig-interface.py
@@ -212,10 +212,10 @@ def extract_swig_modules_dependencies(module_to_submodules, submodule_info):
                     continue
 
                 # Read code
-                with open(header_file) as f:
-                    code = f.read()
-
                 try:
+                    with open(header_file, encoding='utf-8') as f:
+                        code = f.read()
+
                     # Extract type info
                     used_types, declared_types = parse_and_extract_type_info(code)
                 except Exception as e:
diff --git a/utils/pylit/pylit.py b/utils/pylit/pylit.py
index bcd8ec5e0..8c2964fbd 100755
--- a/utils/pylit/pylit.py
+++ b/utils/pylit/pylit.py
@@ -1496,7 +1496,7 @@ def open_streams(infile = '-', outfile = '-', overwrite='update', **keyw):
     if infile == '-':
         in_stream = sys.stdin
     else:
-        in_stream = open(infile, 'r')
+        in_stream = open(infile, 'r', encoding='utf-8')
 
     if outfile == '-':
         out_stream = sys.stdout
@@ -1505,7 +1505,7 @@ def open_streams(infile = '-', outfile = '-', overwrite='update', **keyw):
     elif overwrite == 'update' and is_newer(outfile, infile):
         raise IOError((1, "Output file is newer than input file!", outfile))
     else:
-        out_stream = open(outfile, 'w')
+        out_stream = open(outfile, 'w', encoding='utf-8')
     return (in_stream, out_stream)
 
 # is_newer
@@ -1731,7 +1731,11 @@ def main(args=sys.argv[1:], **defaults):
 
 # Convert and write to out_stream::
 
-    out_stream.write(str(converter))
+    try:
+        out_stream.write(str(converter))
+    except Exception as e:
+        print("Failed to write extract to", out_stream.name)
+        raise
 
     if out_stream is not sys.stdout:
         print("extract written to", out_stream.name)
-- 
2.14.0