setuptools_scm icon indicating copy to clipboard operation
setuptools_scm copied to clipboard

setuptools_scm silently reports garbage version with partial Git clone

Open paugier opened this issue 2 years ago • 7 comments
trafficstars

Readthedocs clones with

git clone --no-single-branch --depth 50 https://github.com/snek5000/snek5000.git
cd snek5000
git checkout --force origin/main
git clean -d -f -f

With such clone,

$ git --git-dir .git describe --dirty --tags --long
fatal: No tags can describe '2a7b9f0b372163f19d0af2dc1cb6752528310530'.
Try --always, or create some tags.

In contrast, git tag gives the right list of tags. Anyway, setuptools_scm bases its analysis on git describe so it gives a wrong version (something like 0.1.dev173+g2a7b9f0).

To get the right version, I need to run:

$ git pull --unshallow
remote: Enumerating objects: 298, done.
remote: Counting objects: 100% (267/267), done.
remote: Compressing objects: 100% (84/84), done.
remote: Total 169 (delta 102), reused 138 (delta 78), pack-reused 0
Receiving objects: 100% (169/169), 23.59 KiB | 23.59 MiB/s, done.
Resolving deltas: 100% (102/102), completed with 22 local objects.
Already up to date.

$ git --git-dir .git describe --dirty --tags --long
0.8.0rc0-285-g2a7b9f0

I don't know what setuptools_scm could do about this case, but it is annoying. Maybe at least a warning?

CC @ashwinvis

paugier avatar Dec 02 '22 10:12 paugier

there are some warnigns on shallw branches by default, its possible they gethidden

can you show the output of SETUPTOOLS_SCM_DEBUG=1 python -m setuptools_scm

RonnyPfannschmidt avatar Dec 02 '22 10:12 RonnyPfannschmidt

we might want to involve readthedocs in this as well as its not clear to me off hand how to fix it for them

RonnyPfannschmidt avatar Dec 02 '22 10:12 RonnyPfannschmidt

@paugier I am not sure what you mean. The final successful rtd build reported the correct version number

snek5000-0.8.0rc1.dev254+g7597f21

And there was no unshallow git operation.

https://readthedocs.org/projects/snek5000/builds/18787743/

https://readthedocs.org/api/v2/build/18787743.txt

ashwinvis avatar Dec 02 '22 11:12 ashwinvis

@ashwinvis I think this is because of the --depth 50. I guess there are more than 50 commits behind the last tag. So before, Git managed to give the right tag. It still works fine with --depth 100.

paugier avatar Dec 02 '22 15:12 paugier

The output of SETUPTOOLS_SCM_DEBUG=1 python -m setuptools_scm:

abs root {'root': '.', 'relative_to': '/tmp/snek5000/pyproject.toml'}
file /tmp/snek5000/pyproject.toml
root '/tmp/snek5000'
relative_to '/tmp/snek5000/pyproject.toml'
dist name: snek5000
version_from_ep setuptools_scm.parse_scm /tmp/snek5000
looking for ep setuptools_scm.parse_scm /tmp/snek5000
found ep EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') in /tmp/snek5000
----
cmd:
     git --git-dir /tmp/snek5000/.git rev-parse --show-prefix
 in: /tmp/snek5000
out:
 

real root /tmp/snek5000
/home/users/augier3pi/Dev/setuptools_scm/src/setuptools_scm/git.py:135: UserWarning: "/tmp/snek5000" is shallow and may cause errors
  warnings.warn(f'"{wd.path}" is shallow and may cause errors')
----
cmd:
     git --git-dir /tmp/snek5000/.git describe --dirty --tags --long --match "*[0-9]*"
 in: /tmp/snek5000
err:
     fatal: No tags can describe 'b1a8932c6ef7037d7ff70c2f8b76f0e0397c51c3'.
    Try --always, or create some tags.

ret: 128
----
cmd:
     git --git-dir /tmp/snek5000/.git rev-parse --verify --quiet HEAD
 in: /tmp/snek5000
out:
     b1a8932c6ef7037d7ff70c2f8b76f0e0397c51c3

----
cmd:
     git --git-dir /tmp/snek5000/.git rev-list HEAD
 in: /tmp/snek5000
out:
     b1a8932c6ef7037d7ff70c2f8b76f0e0397c51c3
    8837551db1944f3ba8860fb7cf555824ba1daaa9
    34c67672246635bac54204a800983674e7979071
    e511c0a2a57c30e8e3f2c9d7190f7ccd352bf7dc
    e70edf64dd3dea705383d9415061c21cb599b2ab
[...]
    d187fc5948d3b32a74eb672596e651f5f6344dc6
    e26856d9a68f10861e8e6ab53c69f40367c43d61
    f630c83ea38e7e5316fe7024df96aebb778692c1
    368d1326786720e053447bfca6f28b156ac7dcb7
    7676a79de5394186431c9e628798fd4813a5a1c2

----
cmd:
     git --git-dir /tmp/snek5000/.git status --porcelain --untracked-files=no
 in: /tmp/snek5000
----
cmd:
     git --git-dir /tmp/snek5000/.git rev-parse --abbrev-ref HEAD
 in: /tmp/snek5000
out:
     HEAD

----
cmd:
     git --git-dir /tmp/snek5000/.git -c log.showSignature=false log -n 1 HEAD --format=%cI
 in: /tmp/snek5000
out:
     2022-12-02T12:44:51+01:00

tag 0.0
tag '0.0' parsed to {'version': '0.0', 'prefix': '', 'suffix': ''}
version pre parse 0.0
version <Version('0.0')>
version 0.0 -> 0.0
EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') <ScmVersion 0.0 dist=161 node=gb1a8932 dirty=False branch=HEAD>
scm version <ScmVersion 0.0 dist=161 node=gb1a8932 dirty=False branch=HEAD>
config {'version_scheme': 'guess-next-dev', 'local_scheme': 'node-and-date'}
ep found: guess-next-dev
version 0.1.dev161
ep found: node-and-date
local_version +gb1a8932
0.1.dev161+gb1a8932

paugier avatar Dec 02 '22 15:12 paugier

@paugier there is a warning about the worktree being shallow

real root /tmp/snek5000
/home/users/augier3pi/Dev/setuptools_scm/src/setuptools_scm/git.py:135: UserWarning: "/tmp/snek5000" is shallow and may cause errors
  warnings.warn(f'"{wd.path}" is shallow and may cause errors')

i believe its necessary to provide some additional tooling to protect peopel from that trap without failing

RonnyPfannschmidt avatar Feb 24 '23 09:02 RonnyPfannschmidt

Based on the current details, I believe it's necessary to change the default from warning to failing on incomplete partial checkouts

RonnyPfannschmidt avatar Mar 13 '23 09:03 RonnyPfannschmidt