# Buggy code
def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
    """
    :param pre_parse: experimental pre_parse action, may change at any time
    """
    if not has_command("git"):
        return

    wd = GitWorkdir.from_potential_worktree(root)
    if wd is None:
        return
    if pre_parse:
        pre_parse(wd)

    out, err, ret = wd.do_ex(describe_command)
    if ret:
        # If 'git describe' failed, try to get the information otherwise.
        rev_node = wd.node()
        dirty = wd.is_dirty()

        if rev_node is None:
            return meta("0.0", distance=0, dirty=dirty)

        return meta(
            "0.0",
            distance=wd.count_all_nodes(),
            node="g" + rev_node,
            dirty=dirty,
            branch=wd.get_branch(),
        )

    # 'out' looks e.g. like 'v1.5.0-0-g4060507' or
    # 'v1.15.1rc1-37-g9bd1298-dirty'.
    if out.endswith("-dirty"):
        dirty = True
        out = out[:-6]
    else:
        dirty = False

    tag, number, node = out.rsplit("-", 2)
    number = int(number)
    branch = wd.get_branch()
    if number:
        return meta(tag, distance=number, node=node, dirty=dirty, branch=branch)
    else:
        return meta(tag, node=node, dirty=dirty, branch=branch)


# Traceback (AssertionError)
looking for ep setuptools_scm.parse_scm_fallback .
root '/Users/twall/plex/rd'
looking for ep setuptools_scm.parse_scm /Users/twall/plex/rd
found ep .git = setuptools_scm.git:parse
cmd 'git rev-parse --show-toplevel'
out b'/Users/twall/plex/rd\n'
real root /Users/twall/plex/rd
cmd 'git describe --dirty --tags --long --match *.*'
out b'3.3.1-rc26-0-g9df187b\n'
cmd 'git rev-parse --abbrev-ref HEAD'
out b'pyplex\n'
tag 3.3.1-rc26
version <LegacyVersion('rc26')>
version None
Traceback (most recent call last):
File "setup.py", line 46, in <module>
entry_points = {
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/anaconda3/lib/python3.6/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools/dist.py", line 370, in __init__
k: v for k, v in attrs.items()
File "/anaconda3/lib/python3.6/distutils/dist.py", line 281, in __init__
self.finalize_options()
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools/dist.py", line 529, in finalize_options
ep.load()(self, ep.name, value)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/integration.py", line 22, in version_keyword
dist.metadata.version = get_version(**value)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/__init__.py", line 119, in get_version
parsed_version = _do_parse(root, parse)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/__init__.py", line 83, in _do_parse
version = version_from_scm(root) or _version_from_entrypoint(
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/__init__.py", line 31, in version_from_scm
return _version_from_entrypoint(root, 'setuptools_scm.parse_scm')
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/__init__.py", line 36, in _version_from_entrypoint
version = ep.load()(root)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/git.py", line 128, in parse
return meta(tag, node=node, dirty=dirty, branch=branch)
File "/Users/twall/plex/rd/search/.venv-3.6/lib/python3.6/site-packages/setuptools_scm/version.py", line 135, in meta
assert tag is not None, 'cant parse version %s' % tag
AssertionError: cant parse version None

# Fixed code
def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
    """
    :param pre_parse: experimental pre_parse action, may change at any time
    """
    if not has_command("git"):
        return

    wd = GitWorkdir.from_potential_worktree(root)
    if wd is None:
        return
    if pre_parse:
        pre_parse(wd)

    out, err, ret = wd.do_ex(describe_command)
    if ret:
        # If 'git describe' failed, try to get the information otherwise.
        rev_node = wd.node()
        dirty = wd.is_dirty()

        if rev_node is None:
            return meta("0.0", distance=0, dirty=dirty)

        return meta(
            "0.0",
            distance=wd.count_all_nodes(),
            node="g" + rev_node,
            dirty=dirty,
            branch=wd.get_branch(),
        )
    else:
        tag, number, node, dirty = _git_parse_describe(out)

        branch = wd.get_branch()
        if number:
            return meta(tag, distance=number, node=node, dirty=dirty, branch=branch)
        else:
            return meta(tag, node=node, dirty=dirty, branch=branch)