setuptools-scm: setuptools_scm breaks pip installing subdirs from git

For example: pip install 'git+https://github.com/swift-nav/libsbp#subdirectory=python'

pip clones the entire repo, including the .git dir, but setuptools_scm breaks

Collecting git+https://github.com/swift-nav/libsbp#subdirectory=python
  Cloning https://github.com/swift-nav/libsbp to /tmp/jck/pip-pjPlzH-build
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/jck/pip-pjPlzH-build/python/setup.py", line 55, in <module>
        zip_safe=False)
      File "/usr/lib64/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/home/jck/.local/share/virtualenvs/a990cbf97408406/lib/python2.7/site-packages/setuptools/dist.py", line 323, in __init__
        _Distribution.__init__(self, attrs)
      File "/usr/lib64/python2.7/distutils/dist.py", line 287, in __init__
        self.finalize_options()
      File "/home/jck/.local/share/virtualenvs/a990cbf97408406/lib/python2.7/site-packages/setuptools/dist.py", line 392, in finalize_options
        ep.load()(self, ep.name, value)
      File "/tmp/jck/pip-pjPlzH-build/python/.eggs/setuptools_scm-1.15.6-py2.7.egg/setuptools_scm/integration.py", line 22, in version_keyword
      File "/tmp/jck/pip-pjPlzH-build/python/.eggs/setuptools_scm-1.15.6-py2.7.egg/setuptools_scm/__init__.py", line 119, in get_version
      File "/tmp/jck/pip-pjPlzH-build/python/.eggs/setuptools_scm-1.15.6-py2.7.egg/setuptools_scm/__init__.py", line 97, in _do_parse
    LookupError: setuptools-scm was unable to detect version for '/tmp/jck/pip-pjPlzH-build/python'.
    
    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
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/jck/pip-pjPlzH-build/python

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 6
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I have the same issue here. In my setup.py:

use_scm_version={"root": "..", "relative_to": __file__}

Running python setup.py --version after git clone is working properly. Trying to install using pip with subdirectory is failling. Little digging with the /tmp directory reveal it’s cause by the creation of pip-egg-info directory. When the directory exists, it fail like this:

looking for ep setuptools_scm.parse_scm_fallback .
found ep pip-egg-info = setuptools_scm.hacks:parse_pip_egg_info
root '/tmp/pip-InXmsP-build/minarca-plugins'
looking for ep setuptools_scm.parse_scm /tmp/pip-InXmsP-build/minarca-plugins
looking for ep setuptools_scm.parse_scm_fallback /tmp/pip-InXmsP-build/minarca-plugins
found ep pip-egg-info = setuptools_scm.hacks:parse_pip_egg_info
pip-egg-info /tmp/pip-InXmsP-build/minarca-plugins/pip-egg-info []
Traceback (most recent call last):
  File "setup.py", line 175, in <module>
    'MinarcaServerInfo = minarca_server_info',
  File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 129, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 372, in __init__
    _Distribution.__init__(self, attrs)
  File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 528, in finalize_options
    ep.load()(self, ep.name, value)
  File "/usr/local/lib/python2.7/dist-packages/setuptools_scm/integration.py", line 22, in version_keyword
    dist.metadata.version = get_version(**value)
  File "/usr/local/lib/python2.7/dist-packages/setuptools_scm/__init__.py", line 119, in get_version
    parsed_version = _do_parse(root, parse)
  File "/usr/local/lib/python2.7/dist-packages/setuptools_scm/__init__.py", line 97, in _do_parse
    "use git+https://github.com/user/proj.git#egg=proj" % root)
LookupError: setuptools-scm was unable to detect version for '/tmp/pip-InXmsP-build/minarca-plugins'.

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 c
heckout 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=pr
oj

If the directory exists, root parameter pass to use_scm_version is discarded and the version is not resolved. Issue is around integration.py:

    # this piece of code is a hack to counter the mistake in root finding
    matching_fallbacks = iter_matching_entrypoints(
        '.', 'setuptools_scm.parse_scm_fallback')
    if any(matching_fallbacks):
        value.pop('root', None)

Since a fallback is found, the pop the root arguments. Not sure to understand the logic. As soon the directory ‘pip-egg-info’ exists, it’s “matching”. The entry point is not execute. To work around this issue, I downgrade the version to 1.5.0 as follow:

setup_requires=["setuptools_scm==1.5.0"],

It is still possible to workaround this issue without downgrading setuptools_scm. It works for me with the following setup (setup.py is one level deeper than repository root)

...
use_scm_version={'relative_to': os.path.dirname(__file__)},
...

Please let me know if this solution has any drawbacks.

If I’m right above, probably not? Though it might be reasoanble to copy the parent directory too and just CD into the sub directory-- but we’d have to verify that is actually the case.