def usort_file()

in usort/api.py [0:0]


def usort_file(path: Path, *, write: bool = False) -> Result:
    """
    Format a single file and return a Result object.

    Ignores any configured :py:attr:`excludes` patterns.
    """

    try:
        config = Config.find(path.parent)
        data = path.read_bytes()
        result = usort(data, config, path)

        if result.output and write:
            path.write_bytes(result.output)

        return result

    except Exception as e:
        return Result(
            path=path,
            error=e,
            timings=get_timings(),
        )