# Buggy code
def tag_to_version(tag):
    trace("tag", tag)
    if "+" in tag:
        warnings.warn("tag %r will be stripped of the local component" % tag)
        tag = tag.split("+")[0]
    # lstrip the v because of py2/py3 differences in setuptools
    # also required for old versions of setuptools

    version = tag.rsplit("-", 1)[-1].lstrip("v")
    if VERSION_CLASS is None:
        return version
    version = pkg_parse_version(version)
    trace("version", repr(version))
    if isinstance(version, VERSION_CLASS):
        return version


# 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 tag_to_version(tag):
    """
    take a tag that might be prefixed with a keyword and return only the version part
    """
    trace("tag", tag)
    if "+" in tag:
        warnings.warn("tag %r will be stripped of the local component" % tag)
        tag = tag.split("+")[0]
    # lstrip the v because of py2/py3 differences in setuptools
    # also required for old versions of setuptools
    prefix_match = TAG_PREFIX.match(tag)
    if prefix_match is not None:
        version = prefix_match.group(1)
    else:
        version = tag
    trace("version pre parse", version)
    if VERSION_CLASS is None:
        return version
    version = pkg_parse_version(version)
    trace("version", repr(version))
    if isinstance(version, VERSION_CLASS):
        return version