pythonsetuptoolssetuptools-scm

How to fix setuptools_scm._file_finders.git listing git files failed?


I am using pyproject.toml to build a package. I use setuptools_scm to automatically determine the version number. I use python version 3.11.2, setuptools 66.1.1 and setuptools-scm 8.1.0.

Here are the relevant parts of pyproject.toml

# For a discussion on single-sourcing the version, see
# https://packaging.python.org/guides/single-sourcing-package-version/
dynamic = ["version"]

[tool.setuptools_scm]
# can be empty if no extra settings are needed, presence enables setuptools-scm

I build the project with

python3 -m build

When I run the build command, I see

ERROR setuptools_scm._file_finders.git listing git files failed - pretending there aren't any

What I've Tried:

How can I fix this error? Are there additional configurations or checks I should perform to ensure setuptools_scm can correctly interact with Git for version determination?

Reproducible example

cd /tmp/
mkdir setuptools_scm_example
cd setuptools_scm_example
git init
touch .gitignore
git add .
git commit -m "Initial commit"

Add the following to pyproject.toml

[build-system]
requires = ["setuptools>=61.0", "setuptools_scm>=7.0"]
build-backend = "setuptools.build_meta"

[project]
name = "example_package"
dynamic = ["version"]

[tool.setuptools_scm]
# No additional configuration needed, but can add if needed

Create and build a python package

mkdir -p example_package
touch example_package/__init__.py
echo "print('Hello from example package')" > example_package/__init__.py
python3 -m build

I see the error

ERROR setuptools_scm._file_finders.git listing git files failed - pretending there aren't any

Solution

  • python3 -m build builds in 2 phases: 1st it builds sdist and then it builds wheel from the sdist in an isolated environment where there is no .git directory. It doesn't matter because at the wheel building phase version is already set in sdist and build gets the version from sdist, not from setuptools_scm. In short: you may safely ignore the error.

    Reference: https://github.com/pypa/setuptools-scm/issues/997 . Found in https://github.com/pypa/setuptools-scm/issues?q=is%3Aissue+setuptools_scm._file_finders.git

    Another approach to try: prevent build isolation, install build dependencies into the current environment and build sdist and wheel explicitly:

    python3 -m pip install build setuptools-scm
    python3 -m build --no-isolation --sdist --wheel