def get_version(package: Union[Path, str]) -> str:
path = Path(package)<EOL>if not path.suffix and len(path.parts) == <NUM_LIT:1>:  <EOL><INDENT>v = get_version_from_metadata(package)<EOL>if v:<EOL><INDENT>return str(v)<EOL><DEDENT><DEDENT>if path.suffix != "<STR_LIT>":<EOL><INDENT>msg = f"<STR_LIT>"<EOL>if path.suffix:<EOL><INDENT>msg += f"<STR_LIT>"<EOL><DEDENT>raise ValueError(msg)<EOL><DEDENT>if path.name == "<STR_LIT>":<EOL><INDENT>name = path.parent.name<EOL>parent = path.parent.parent<EOL><DEDENT>else:<EOL><INDENT>name = path.with_suffix("<STR_LIT>").name<EOL>parent = path.parent<EOL><DEDENT>return str(<EOL>get_version_from_dirname(name, parent)<EOL>or get_version_from_git(parent)<EOL>or get_version_from_metadata(name, parent)<EOL>or "<STR_LIT>"<EOL>)<EOL>
Get the version of a package or module
    Pass a module path or package name.
    The former is recommended, since it also works for not yet installed packages.
    Supports getting the version from
    #. The directory name (as created by ``setup.py sdist``)
    #. The output of ``git describe``
    #. The package metadata of an installed package
       (This is the only possibility when passing a name)
    Args:
       package: package name or module path (``…/module.py`` or ``…/module/__init__.py``)