Setuptools: build_meta does not include setup.py

Created on 8 Oct 2018  路  2Comments  路  Source: pypa/setuptools

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:

  • anyone beforehand calls python setup.py sdist,
  • when there's a distutils extension that automatically pulls in setup.py (such as setuptools-scm),
  • when some config value pulls in (one in MANIFEST.in, setup.cfg, setup.py).
Needs Implementation bug critical help wanted

Most helpful comment

Working on this based on the PyPA sprint : https://github.com/orgs/pypa/projects/1

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings