# Buggy code
def parse(root, describe_command=DEFAULT_DESCRIBE):
    real_root, _, ret = do_ex("git rev-parse --show-toplevel", root)
    if ret:
        return
    trace("real root", real_root)
    if abspath(realpath(real_root)) != abspath(realpath(root)):
        return
    rev_node, _, ret = do_ex("git rev-parse --verify --quiet HEAD", root)
    if ret:
        return meta("0.0")
    rev_node = rev_node[:7]
    out, err, ret = do_ex(describe_command, root)
    if "-" not in out and "." not in out:
        revs = do("git rev-list HEAD", root)
        count = revs.count("\n")
        if ret:
            out = rev_node
        return meta("0.0", distance=count + 1, node=out)
    if ret:
        return
    dirty = out.endswith("-dirty")
    if dirty:
        out = out.rsplit("-", 1)[0]

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


# Traceback (LookupError)
(env35) C:\Users\scrut\code\phi\auth [develop +0 ~4 -0 | +0 ~16 -0 !]> dir


Directory: C:\Users\scrut\code\phi\auth


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/12/2016  12:38 PM                .git
d-----        6/12/2016  12:24 PM                .tox
d-----        6/11/2016   9:02 PM                doc
d-----        6/11/2016   9:41 PM                src
d-----        6/11/2016   9:02 PM                test
-a----        6/11/2016   9:02 PM            395 .gitattributes
-a----        6/12/2016  12:22 PM           1584 .gitignore
-a----        6/11/2016   9:02 PM            116 .travis.yml
-a----        6/11/2016   9:02 PM           1077 LICENSE.rst
-a----        6/11/2016   9:02 PM             40 MANIFEST.in
-a----        6/12/2016  12:09 PM            897 README.rst
-a----        6/12/2016  12:38 PM           1452 setup.py
-a----        6/11/2016   9:02 PM            610 tox.ini


(env35) C:\Users\scrut\code\phi\auth [develop +0 ~4 -0 | +0 ~16 -0 !]> python setup.py egg_info
Traceback (most recent call last):
File "setup.py", line 58, in <module>
entry_points={},
File "c:\users\scrut\appdata\local\programs\python\python35-32\Lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Users\scrut\code\env35\lib\site-packages\setuptools\dist.py", line 272, in __init__
_Distribution.__init__(self,attrs)
File "c:\users\scrut\appdata\local\programs\python\python35-32\Lib\distutils\dist.py", line 281, in __init__
self.finalize_options()
File "C:\Users\scrut\code\env35\lib\site-packages\setuptools\dist.py", line 327, in finalize_options
ep.load()(self, ep.name, value)
File "c:\users\scrut\code\phi\auth\.eggs\setuptools_scm-1.11.0-py3.5.egg\setuptools_scm\integration.py", line 19, in version_keyword
File "c:\users\scrut\code\phi\auth\.eggs\setuptools_scm-1.11.0-py3.5.egg\setuptools_scm\__init__.py", line 104, in get_version
File "c:\users\scrut\code\phi\auth\.eggs\setuptools_scm-1.11.0-py3.5.egg\setuptools_scm\__init__.py", line 82, in _do_parse
LookupError: setuptools-scm was unable to detect version for 'C:\\Users\\scrut\\code\\phi\\auth'.

Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

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, describe_command=DEFAULT_DESCRIBE):
    real_root, _, ret = do_ex("git rev-parse --show-toplevel", root)
    if ret:
        return
    trace("real root", real_root)
    if normcase(abspath(realpath(real_root))) != normcase(abspath(realpath(root))):
        return
    rev_node, _, ret = do_ex("git rev-parse --verify --quiet HEAD", root)
    if ret:
        return meta("0.0")
    rev_node = rev_node[:7]
    out, err, ret = do_ex(describe_command, root)
    if "-" not in out and "." not in out:
        revs = do("git rev-list HEAD", root)
        count = revs.count("\n")
        if ret:
            out = rev_node
        return meta("0.0", distance=count + 1, node=out)
    if ret:
        return
    dirty = out.endswith("-dirty")
    if dirty:
        out = out.rsplit("-", 1)[0]

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