I have a flat-layout project like this:
├── project_name
│ └── ...
├── .gitignore
├── pyproject.toml
└── ...
I follow the setuptools
docs to compose the pyproject.toml
like this:
[build-system]
requires = ['setuptools>=45', 'setuptools_scm[toml]>=6.2']
[project]
name = 'project_name'
version = '0.0.1'
[tool.setuptools.exclude-package-data]
"*" = [".gitignore"]
However, when I do
python3 -m build --sdist
I get the .gitignore
file in the resulting *.tar.gz
file.
I can forcefully exclude the file using a MANIFEST.in
:
exclude .gitignore
What the use of the [tool.setuptools.exclude-package-data]
section, then? Can I do the job without the MANIFEST.in
file?
Do I misuse the section? From what the building process reports, I guess the '*'
there means the project_name
directory. Is there any config key to exclude the .*
files from the root of the sdist
package?
An MWE for @sinoroc (to be run in a shell):
# make a dedicated directory and enter it
mkdir package_name
pushd package_name
# make two empty files (only the first one is mandatory)
touch .gitignore README
# fill pyproject.toml
echo "build-system.requires = ['setuptools', 'setuptools_scm[toml]']" >> pyproject.toml
echo "project = {name = 'package_name', version = '0.0.1'}" >> pyproject.toml
echo "[tool.setuptools_scm]" >> pyproject.toml
# prepare a virtual environment
python -m venv venv
source venv/bin/activate
python -m pip install -U pip setuptools build
# commit .gitignore
git init
git add -f .gitignore
git commit -m "add .gitignore"
# build a package
python -m build --sdist
# list the files in the package
tar --list -f dist/package_name-0.0.1.tar.gz
# exit (optional)
deactivate
popd
This makes the following file tree:
├── .git
│ └── ...
├── dist
│ └── package_name-0.0.1.tar.gz
├── package_name.egg-info
│ └── ...
├── venv
│ └── ...
├── .gitignore
├── pyproject.toml
└── README
The pyproject.toml
file has the following content:
build-system.requires = ['setuptools', 'setuptools_scm[toml]']
project = {name = 'package_name', version = '0.0.1'}
[tool.setuptools_scm]
The README
and .gitignore
files are empty. The latter has to be committed for the MWE to work.
It looks that it's the setuptools_scm
that's to blame for the inclusion of .gitignore
. The latter should be committed.