1313from __future__ import annotations
1414
1515import itertools
16- import os
1716from os import PathLike
17+ from pathlib import Path
1818from typing import Any , Iterable , Optional , Tuple , Union
1919
2020import numpy as np
@@ -258,9 +258,10 @@ def load_truetype_font(path: Union[str, PathLike[str]], tile_width: int, tile_he
258258
259259 This function is provisional. The API may change.
260260 """
261- if not os .path .exists (path ):
262- raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
263- cdata = lib .TCOD_load_truetype_font_ (str (path ).encode (), tile_width , tile_height )
261+ path = Path (path )
262+ if not path .exists ():
263+ raise RuntimeError (f"File not found:\n \t { path .resolve ()} " )
264+ cdata = lib .TCOD_load_truetype_font_ (bytes (path ), tile_width , tile_height )
264265 if not cdata :
265266 raise RuntimeError (ffi .string (lib .TCOD_get_error ()))
266267 return Tileset ._claim (cdata )
@@ -287,9 +288,10 @@ def set_truetype_font(path: Union[str, PathLike[str]], tile_width: int, tile_hei
287288 This function does not support contexts.
288289 Use :any:`load_truetype_font` instead.
289290 """
290- if not os .path .exists (path ):
291- raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
292- if lib .TCOD_tileset_load_truetype_ (str (path ).encode (), tile_width , tile_height ):
291+ path = Path (path )
292+ if not path .exists ():
293+ raise RuntimeError (f"File not found:\n \t { path .resolve ()} " )
294+ if lib .TCOD_tileset_load_truetype_ (bytes (path ), tile_width , tile_height ):
293295 raise RuntimeError (ffi .string (lib .TCOD_get_error ()))
294296
295297
@@ -306,9 +308,10 @@ def load_bdf(path: Union[str, PathLike[str]]) -> Tileset:
306308
307309 .. versionadded:: 11.10
308310 """ # noqa: E501
309- if not os .path .exists (path ):
310- raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
311- cdata = lib .TCOD_load_bdf (str (path ).encode ())
311+ path = Path (path )
312+ if not path .exists ():
313+ raise RuntimeError (f"File not found:\n \t { path .resolve ()} " )
314+ cdata = lib .TCOD_load_bdf (bytes (path ))
312315 if not cdata :
313316 raise RuntimeError (ffi .string (lib .TCOD_get_error ()).decode ())
314317 return Tileset ._claim (cdata )
@@ -335,12 +338,13 @@ def load_tilesheet(
335338
336339 .. versionadded:: 11.12
337340 """
338- if not os .path .exists (path ):
339- raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
341+ path = Path (path )
342+ if not path .exists ():
343+ raise RuntimeError (f"File not found:\n \t { path .resolve ()} " )
340344 mapping = []
341345 if charmap is not None :
342346 mapping = list (itertools .islice (charmap , columns * rows ))
343- cdata = lib .TCOD_tileset_load (str (path ). encode ( ), columns , rows , len (mapping ), mapping )
347+ cdata = lib .TCOD_tileset_load (bytes (path ), columns , rows , len (mapping ), mapping )
344348 if not cdata :
345349 _raise_tcod_error ()
346350 return Tileset ._claim (cdata )
0 commit comments