# Buggy code
def parse(root):
    l = do("hg id -i -t", root).split()
    node = l.pop(0)
    tags = tags_to_versions(l)
    # filter tip in degraded mode on old setuptools
    tags = [x for x in tags if x != "tip"]
    dirty = node[-1] == "+"
    if tags:
        return meta(tags[0], dirty=dirty)

    if node.strip("+") == "0" * 12:
        trace("initial node", root)
        return meta("0.0", dirty=dirty)

    cmd = 'hg parents --template "{latesttag} {latesttagdistance}"'
    out = do(cmd, root)
    try:
        tag, dist = out.split()
        if tag == "null":
            tag = "0.0"
            dist = int(dist) + 1
        return _hg_tagdist_normalize_tagcommit(root, tag, dist, node)
    except ValueError:
        pass  # unpacking failed, old hg


# Traceback (LookupError)
$ python setup.py test
Traceback (most recent call last):
File "setup.py", line 61, in <module>
setuptools.setup(**setup_params)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/dist.py", line 272, in __init__
_Distribution.__init__(self,attrs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 281, in __init__
self.finalize_options()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/dist.py", line 327, in finalize_options
ep.load()(self, ep.name, value)
File "/Users/jaraco/Dropbox/code/yg/support/yg.jenkins/.eggs/setuptools_scm-1.10.0-py3.5.egg/setuptools_scm/integration.py", line 19, in version_keyword
File "/Users/jaraco/Dropbox/code/yg/support/yg.jenkins/.eggs/setuptools_scm-1.10.0-py3.5.egg/setuptools_scm/__init__.py", line 102, in get_version
File "/Users/jaraco/Dropbox/code/yg/support/yg.jenkins/.eggs/setuptools_scm-1.10.0-py3.5.egg/setuptools_scm/__init__.py", line 80, in _do_parse
LookupError: setuptools-scm was unable to detect version for '/Users/jaraco/Dropbox/code/yg/support/yg.jenkins'.

Make sure you're not using GitHub's tarballs (or similar ones), as those don't contain the necessary metadata. Use PyPI's tarballs instead.

For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj

# Fixed code
def parse(root):
    l = do("hg id -i -t", root).split()
    node = l.pop(0)
    tags = tags_to_versions(l)
    # filter tip in degraded mode on old setuptools
    tags = [x for x in tags if x != "tip"]
    dirty = node[-1] == "+"
    if tags:
        return meta(tags[0], dirty=dirty)

    if node.strip("+") == "0" * 12:
        trace("initial node", root)
        return meta("0.0", dirty=dirty)

    # the newline is needed for merge stae, see issue 72
    cmd = 'hg parents --template "{latesttag} {latesttagdistance}\n"'
    out = do(cmd, root)
    try:
        # in merge state we assume parent 1 is fine
        tag, dist = out.splitlines()[0].split()
        if tag == "null":
            tag = "0.0"
            dist = int(dist) + 1
        return _hg_tagdist_normalize_tagcommit(root, tag, dist, node)
    except ValueError:
        pass  # unpacking failed, old hg