sdist does not run `git archive`
If the repository is setup with a .gitattributes, then running hatch build or python3 -m build fails to take into account the settings there. For example a repo setup with https://setuptools-scm.readthedocs.io/en/latest/usage/#git-archives does not replace .git_archival.txt properly. For the most part it can be ok since the PKG-INFO is included, but it can have other unexpected consequences.
For the most part it can be ok since the
PKG-INFOis included, but it can have other unexpected consequences.
Which would that be?
I've never included .git_archival.txt in my sdists and never ran into any issues (using setuptools-scm and hatch-vcs). What would you need this file for at build time or at runtime?
.git_archival.txt is needed if you build/install from a git archive instead of a git checkout.
As mentioned, generally for the sdist itself it is fine because PKG-INFO is included there instead, but there could be cases where the lack of git archiving can create problems, e.g. mixed language projects that use the .git_archival.txt metadata for versioning or other .gitattributes features.
Are you saying that file should always be included like these? https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection
If so I'm fine with that, I just have never heard of that file before.
.git_archival.txtis needed if you build/install from a git archive instead of a git checkout.
Exactly. But not for building from am sdist.
It is required for creating the sdist from an archived git repository, though. But that's handled through git-archive.
Are you saying that file should always be included like these? https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection
No, this is just a regular file in a git repository: e.g.
https://github.com/scikit-build/scikit-build-core/blob/main/.git_archival.txt
The key thing is the usage of .gitattributes which converts
ref-names: $Format:%D$
To
ref-names: v0.22.0
You can download the zip archive and open the .git_archival.txt in action. That is what allows setuptools_scm to have a version number based on a git archive.
Are you saying that file should always be included like these? https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection
I think they're saying you essentially should run the substitution of the file's contents that git-archive would normally perform, and then package the file.
I feel this is out of scope for hatchling but that may just be me.
Oh I see, thanks for explaining. In that case I think this would be a feature request for: https://github.com/ofek/hatch-vcs
There is also a desire for an option that would trigger inclusion to be entirely based on the git CLI, effectively bypassing everything else.
Indeed at the moment it is not a bug or anything, it's just an unexpected behavior that developers/packagers would encounter.
Why I think it is unexpected is because by default, hatch includes only the git sources as if it went trhough .gitignore. So it is a gray area where does the git interoperability end. The substitution through .gitattributes is one of them, and .git_archival.txt is just a popular example for this