from subprocess import CalledProcessError, check_output def root() -> str: try: root = check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip() return root except CalledProcessError as err: raise OSError("Current working directory is not a git repository") from err def repository_name() -> str: repo_path = root() return repo_path.split("/")[-1]