Search code examples
pythonsetuptoolspython-packagingsetuptools-scm

setuptools_scm not working with `pip install .` in case of .git in parent folder


I have two or more Python packages in one versioned folder:

.
├── .git
├── api
│   ├── mf_hub_api
│   │   └── __init__.py
│   └── setup.py
├── pkg
│   ├── mf_hub
│   │   └── __init__.py
│   └── setup.py
└── README.rst

From both ./api and pkg python package pip install -e . work well but pip install . give me the traceback:

mf_hub/pkg$ pip install .
Processing .../mf_hub/pkg
...
LookupError: setuptools-scm was unable to detect version for '/tmp'.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

My config.py::

mf_hub$ cat pkg/setup.py
from setuptools import find_packages
from setuptools import setup

requirements = """
pip
setuptools
wheel
setuptools_scm
"""

setup(
    name="mf_hub",
    setup_requires=["setuptools_scm"],
    use_scm_version={
        "write_to": "../version.txt",
        "root": "..",
        "relative_to": __file__,
    },
    packages=find_packages(),
    test_suite="tests",
    install_requires=requirements,
    include_package_data=True,
    zip_safe=False,
)
mf_hub$

What could be a temporary workaround ?

I saw that there is an open issue related to that: https://github.com/pypa/setuptools_scm/issues/357


Solution

  • You have to use in-tree-build feature. It's enabled by default in newer pip releases. There are two solutions:

    1. update pip:
    pip install -U pip
    pip install .
    
    1. or use the feature directly:
    pip install --use-feature=in-tree-build .