def resolve_user_filepath(filepath: str, ctx: t.Optional[str]) -> str:
    """Resolve the abspath of a filepath provided by user. User provided file path can:
    * be a relative path base on ctx dir
    * contain leading "~" for HOME directory
    * contain environment variables such as "$HOME/workspace"
    """
    # Return if filepath exist after expanduser

    _path = os.path.expanduser(os.path.expandvars(filepath))

    # Try finding file in ctx if provided
    if not os.path.isabs(_path) and ctx:
        _path = os.path.expanduser(os.path.join(ctx, filepath))

    if os.path.exists(_path):
        return os.path.realpath(_path)

    raise FileNotFoundError(f"file {filepath} not found")
Resolve the abspath of a filepath provided by user. User provided file path can:
* be a relative path base on ctx dir
* contain leading "~" for HOME directory
* contain environment variables such as "$HOME/workspace"
src/bentoml/_internal/utils/filesystem.py