Normalize given path in various different forms.

    >>> normpath("/tmp/../etc/hosts")
    '/etc/hosts'
    >>> normpath("~root/t")
    '/root/t'

def normpath(path):
    """Normalize given path in various different forms.

    >>> normpath("/tmp/../etc/hosts")
    '/etc/hosts'
    >>> normpath("~root/t")
    '/root/t'
    """
    funcs = [os.path.normpath, os.path.abspath]
    if "~" in path:
        funcs = [os.path.expanduser] + funcs

    return chaincalls(funcs, path)