pypa / pypa/setuptools

[BUG] build command copies extension sources (.c, .cpp files) to build/lib directory

Open
#5,133 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Needs Triage
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

setuptools version

80.9.0

Python version

Python 3.11.13

OS

RHEL 8

Additional environment information

Only happens when both pyproject.toml and setup.py are present.

Description

python setup.py build copies the extension sources i.e. the .cpp files to the lib directory along with the generated .so files.

Expected behavior

python setup.py build should only copy the .so files for extensions, not the extension sources.

How to Reproduce

Run python setup.py build in a project containing an extension, the extension sources will be copied to the lib directory.

pyproject.toml contains:

[project]
name="foo"
version="1.0"

setup.py contains:

from setuptools import setup, Extension

setup(
    ext_modules=[
        Extension("foo.extension", ["src/foo/extension/bar.cpp"]),
    ],
)

project structure:

 .
├── pyproject.toml
├── setup.py
└── src
    └── foo
        └── extension
            └── bar.cpp

3 directories, 3 files

After running build command:

.
├── build
│   ├── lib.linux-x86_64-cpython-311
│   │   └── foo
│   │       ├── extension
│   │       │   └── bar.cpp
│   │       └── extension.cpython-311-x86_64-linux-gnu.so
│   └── temp.linux-x86_64-cpython-311
│       └── src
│           └── foo
│               └── extension
│                   └── bar.o
├── pyproject.toml
├── setup.py
└── src
    ├── foo
    │   └── extension
    │       └── bar.cpp
    └── foo.egg-info
        ├── PKG-INFO
        ├── SOURCES.txt
        ├── dependency_links.txt
        └── top_level.txt

12 directories, 10 files
Output

Output of python setup.py build

Could not find an up-to-date installation of `packaging`. License expressions might not be validated. To enforce validation, please install `packaging>=24.2`.
Note: NumExpr detected 10 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 8.
NumExpr defaulting to 8 threads.
running build
running build_py
running egg_info
creating src/foo.egg-info
writing src/foo.egg-info/PKG-INFO
writing dependency_links to src/foo.egg-info/dependency_links.txt
writing top-level names to src/foo.egg-info/top_level.txt
/usr/local/python/python-3.11/std/lib64/python3.11/site-packages/pbr/git.py:28: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
writing manifest file 'src/foo.egg-info/SOURCES.txt'
reading manifest file 'src/foo.egg-info/SOURCES.txt'
writing manifest file 'src/foo.egg-info/SOURCES.txt'
creating build/lib.linux-x86_64-cpython-311/foo/extension
copying src/foo/extension/bar.cpp -> build/lib.linux-x86_64-cpython-311/foo/extension
running build_ext
INFO: Disabling color, you really want to install colorlog.
Disabling color, you really want to install colorlog.
building 'foo.extension' extension
creating build/temp.linux-x86_64-cpython-311/src/foo/extension
/opt/rh/gcc-toolset-10/root/usr/bin/g++ -pthread -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/codemill/rajputa/dessetuptools/venv/include -I/opt/python/python-3.11/include/python3.11 -c src/foo/extension/bar.cpp -o build/temp.linux-x86_64-cpython-311/src/foo/extension/bar.o
/opt/rh/gcc-toolset-10/root/usr/bin/g++ -pthread -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -shared build/temp.linux-x86_64-cpython-311/src/foo/extension/bar.o -L/opt/python/python-3.11/lib64 -o build/lib.linux-x86_64-cpython-311/foo/extension.cpython-311-x86_64-linux-gnu.so

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the minimal pyproject.toml, setup.py, and src/foo/extension/bar.cpp project, then trace the build command's handling of Python sources and extension sources. Done means the build/lib directory contains the generated .so without copying bar.cpp, while extension compilation still succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.