pypa / setuptools_scm

the blessed package to manage your versions by scm tags

Home Page:https://setuptools-scm.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build process seems to `git add _version.py` in spite of .gitignore

PHvL opened this issue · comments

We are using setuptools_scm==8.0.4 on python 3.11 in a package dssnat with the pyproject.toml

[build-system]
requires = [
    "setuptools>=64",
    "setuptools_scm>=8",
    "wheel"
]
build-backend = "setuptools.build_meta"

[project]
name = "dssnat"
dynamic = ["version"]
...

[tool.setuptools_scm]
version_file = "dssnat/_version.py"

In a clean workdir with a new tag

> git tag -a -m "test tag" v0.120.1
> git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
> git describe --long --tags --dirty
v0.120.1-0-g79eea3b1

calling setuptools_scm results in the expected version tag equal to the git tag

> python -m setuptools_scm
0.120.1

But building the package a different version tag is used

> python -m build
...
creating dssnat-0.120.2.dev0+g79eea3b1.d20231020
...
Successfully built dssnat-0.120.2.dev0+g79eea3b1.d20231020.tar.gz and dssnat-0.120.2.dev0+g79eea3b1.d20231020-py3-none-any.whl

Looking at the git status, we can see that the build process added the dssnat/_version.py (included in .gitignore) and hence dirtied the work dir:

> git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   dssnat/_version.py

no changes added to commit (use "git add" and/or "git commit -a")
> git describe --long --tags --dirty
v0.120.1-0-g79eea3b1-dirty
> python -m setuptools_scm
0.120.2.dev0+g79eea3b1.d20231020

This happens on my windows 11 machine as well as in our gitlab runners (using debian/bookworm based docker images).

As there's no git repo linked and the package is not on pypi

I'll have to presume the version file wasn't deleted from git after adding it to git ignore

Thanks for the quick reply. Indeed, somehow the _version.py got committed.