| 1249 | |
| 1250 | |
| 1251 | class _LuatexKpsewhich: |
| 1252 | @cache # A singleton. |
| 1253 | def __new__(cls): |
| 1254 | self = object.__new__(cls) |
| 1255 | self._proc = self._new_proc() |
| 1256 | return self |
| 1257 | |
| 1258 | def _new_proc(self): |
| 1259 | return subprocess.Popen( |
| 1260 | ["luatex", "--luaonly", str(cbook._get_data_path("kpsewhich.lua"))], |
| 1261 | # mktexpk logs to stderr; suppress that. |
| 1262 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, |
| 1263 | # Store generated pk fonts in our own cache. |
| 1264 | env={"MT_VARTEXFONTS": str(Path(mpl.get_cachedir(), "vartexfonts")), |
| 1265 | **os.environ}) |
| 1266 | |
| 1267 | def search(self, filename): |
| 1268 | if self._proc.poll() is not None: # Dead, restart it. |
| 1269 | self._proc = self._new_proc() |
| 1270 | self._proc.stdin.write(os.fsencode(filename) + b"\n") |
| 1271 | self._proc.stdin.flush() |
| 1272 | out = self._proc.stdout.readline().rstrip() |
| 1273 | return None if out == b"nil" else os.fsdecode(out) |
| 1274 | |
| 1275 | |
| 1276 | @lru_cache |
no outgoing calls
no test coverage detected
searching dependent graphs…