29
29
30
30
import numpy as np
31
31
32
- from matplotlib import rcParams
32
+ from matplotlib import cbook , rcParams
33
33
34
34
_log = logging .getLogger (__name__ )
35
35
@@ -990,6 +990,8 @@ def find_tex_file(filename, format=None):
990
990
kpathsea. It is also available as part of MikTeX, a popular
991
991
distribution on Windows.
992
992
993
+ *If the file is not found, an empty string is returned*.
994
+
993
995
Parameters
994
996
----------
995
997
filename : string or bytestring
@@ -1015,11 +1017,16 @@ def find_tex_file(filename, format=None):
1015
1017
if format is not None :
1016
1018
cmd += ['--format=' + format ]
1017
1019
cmd += [filename ]
1018
- _log .debug ('find_tex_file(%s): %s' , filename , cmd )
1019
- pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE )
1020
- result = pipe .communicate ()[0 ].rstrip ()
1021
- _log .debug ('find_tex_file result: %s' , result )
1022
- return result .decode ('ascii' )
1020
+ try : # Below: strip final newline.
1021
+ result = cbook ._check_and_log_subprocess (cmd , _log )[:- 1 ]
1022
+ except RuntimeError :
1023
+ return ''
1024
+ if os .name == 'nt' :
1025
+ # On Windows only, kpathsea appears to use utf-8 output(?); see
1026
+ # __win32_fputs in the kpathsea sources and mpl issue #11848.
1027
+ return result .decode ('utf-8' )
1028
+ else :
1029
+ return os .fsdecode (result )
1023
1030
1024
1031
1025
1032
@lru_cache ()
0 commit comments