Skip to content

Proper way to build setuptools-scm without .git directory? #1103

Closed
@Ecordonnier

Description

@Ecordonnier

Hi,
I would appreciate some pointers to solve this issue. I'm not sure whether it is an issue in setuptools-scm itself or not, but I'm missing a lot of context (I don't have an advanced knowledge of python), so maybe the issue is obvious to you.
I am consuming setuptools-scm as part of yocto, which is a build-system for embedded-systems which builds almost everything from scratch (including python and other build-tools).
As part of this build-system, a file describes how to build setuptools-scm.
It works more or less this way:

Looking at the call-stack, I can see that setuptools's function walk_revctrl calls those functions from setuptools_scm:

File "/home/ecordonnier/dev/poky/build/tmp/work/x86_64-linux/python3-setuptools-scm-native/8.0.4/recipe-sysroot-native/usr/lib/python3.12/site-packages/setuptools/command/sdist.py", line 16, in walk_revctrl
    yield from ep.load()(dirname)
File "/home/ecordonnier/dev/poky/build/tmp/work/x86_64-linux/python3-setuptools-scm-native/8.0.4/setuptools-scm-8.0.4/src/setuptools_scm/_file_finders/__init__.py", line 103, in find_files
    res: list[str] = command(path)
File "/home/ecordonnier/dev/poky/build/tmp/work/x86_64-linux/python3-setuptools-scm-native/8.0.4/setuptools-scm-8.0.4/src/setuptools_scm/_file_finders/git.py", line 103, in git_find_files
    git_files, git_dirs = _git_ls_files_and_dirs(toplevel)
File "/home/ecordonnier/dev/poky/build/tmp/work/x86_64-linux/python3-setuptools-scm-native/8.0.4/setuptools-scm-8.0.4/src/setuptools_scm/_file_finders/git.py", line 74, in _git_ls_files_and_dirs
    for line in traceback.format_stack(): 

The issue is that the setuptools-scm tarball does not contain a .git directory. Thus this code in ./src/setuptools_scm/_file_finders/git.py is detecting the root of my git repository (which is completely unrelated and quite huge):

def git_find_files(path: _t.PathT = "") -> list[str]:
    toplevel = _git_toplevel(os.fspath(path))

This code then calls "git archive --prefix toplevel HEAD" (function _git_ls_files_and_dirs) on my huge repository, and takes an hour to complete and consumes a massive amount of memory.

Do you know where the issue is? Is the logic used to build setuptools-scm wrong? Or is the issue in setuptools-scm itself?

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions