from pathlib import Path
import click
import pathlib


def ensure_posixpath(fp):
  """Ensures filepath is pathlib.Path
  :param fp: a (str, LazyFile, PosixPath)
  :returns: a PosixPath filepath object
  """
  if type(fp) == str:
    fpp = Path(fp)
  elif type(fp) == click.utils.LazyFile:
    fpp = Path(fp.name)
  elif type(fp) == pathlib.PosixPath:
    fpp = fp
  elif type(fp) == pathlib.WindowsPath:
    fpp = Path(fp.as_posix())
  else:
    raise TypeError('{} is not a valid filepath type'.format(type(fp)))
  return fpp