When someone invokes the build operation via the build_meta (via https://github.com/pypa/setuptools/blob/master/setuptools/build_meta.py#L170 - https://www.python.org/dev/peps/pep-0517/#build-sdist) the setup.py is no longer automatically packaged.
In case of python setup.py sdist what ensured that this will happen is https://github.com/python/cpython/blob/master/Lib/distutils/command/sdist.py#L250. Here distribution.script_name is set to setup.py when called via python setup.py sdist. This is not set though when calling it directly via build_meta so packaging setup.py is safely ignored.
Note the files to package is determined while running egg_info, and this is re-used across runs (by reading SOURCES.txt). Therefore this bug is hidden when:
python setup.py sdist,MANIFEST.in, setup.cfg, setup.py).Here is a minimal script that confirms the bug.
Here is a script to create an MWE repo:
#!/usr/bin/bash
# Make the directory
mkdir mypkg
cd mypkg
mkdir mypkg
touch mypkg/__init__.py
# Make setup.py
cat << EOF > setup.py
from setuptools import setup
setup(name="mypkg", packages=["mypkg"], version="0.0.1")
EOF
After running it, cd into mypkg and run:
python -c 'from setuptools.build_meta import build_sdist; build_sdist(".")'
This will build the sdist, and you can confirm that setup.py is not included in the tarball:
$ tar -tf mypkg-0.0.1.tar.gz
mypkg-0.0.1/
mypkg-0.0.1/PKG-INFO
mypkg-0.0.1/mypkg/
mypkg-0.0.1/mypkg/__init__.py
mypkg-0.0.1/mypkg.egg-info/
mypkg-0.0.1/mypkg.egg-info/PKG-INFO
mypkg-0.0.1/mypkg.egg-info/SOURCES.txt
mypkg-0.0.1/mypkg.egg-info/dependency_links.txt
mypkg-0.0.1/mypkg.egg-info/top_level.txt
mypkg-0.0.1/setup.cfg
A PR with a failing test that basically repeats those steps and asserts that setup.py is included in the resulting tarball would be accepted, as would a fix for said test.
Working on this based on the PyPA sprint : https://github.com/orgs/pypa/projects/1
Most helpful comment
Working on this based on the PyPA sprint : https://github.com/orgs/pypa/projects/1