diff --git a/Lib/fontParts/base/normalizers.py b/Lib/fontParts/base/normalizers.py index f0497390..14018bfb 100644 --- a/Lib/fontParts/base/normalizers.py +++ b/Lib/fontParts/base/normalizers.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any, Optional, Tuple, Type, Union from collections import Counter from fontTools.misc.fixedTools import otRound +from pathlib import Path from fontParts.base.annotations import ( T, @@ -1138,17 +1139,22 @@ def normalizeGlyphNote(value: str) -> str: # File Path -def normalizeFilePath(value: str) -> str: +def normalizeFilePath(value: Union[str, Path]) -> str: """Normalize a file path. - :param value: The file path to normalize as a :class:`str`. - :return: A :class:`str` representing the noramlized file path. - :raises TypeError if `value` is not a :class:`str`. + Relative paths are resolved automatically. + + :param value: The file path to normalize as a :class:`str` or :class:`pathlib.Path`. + :return: A :class:`str` representing the normalized file path. + :raises TypeError if `value` is not a :class:`str` or :class:`pathlib.Path`. + :raises FileNotFoundError: If the file path cannot be resolved because it does not exist. """ - if not isinstance(value, str): - raise TypeError(f"File paths must be strings, not {type(value).__name__}.") - return value + if not isinstance(value, (str, Path)): + raise TypeError( + f"File paths must be strings or Path objects, not {type(value).__name__}." + ) + return str(Path(value).resolve()) # Interpolation