pypa / pypa/setuptools

[BUG] top_level.txt is incorrect when `ext_package` is set

Open
#3,524 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

setuptools version

setuptools==65.0.0

Python version

python 3.10.4

OS

ubuntu 22.04

Additional environment information

appears independent of environment

Description

when ext_package is used, any ext_modules show up in top_level.txt (though they should not)

Expected behavior

I expect the contents of top_level.txt to respect ext_package -- in the below example I should only see a in top_level.txt

How to Reproduce

install this and then inspect top_level.txt

# ==> a/__init__.py <==
from . import _hello_world
# ==> _hello_world.c <==
#include <Python.h>

static PyObject* _hello_world(PyObject* self) {
    return PyUnicode_FromString("hello world");
}

static struct PyMethodDef methods[] = {
    {"hello_world", (PyCFunction)_hello_world, METH_NOARGS},
    {NULL, NULL}
};

static struct PyModuleDef module = {
    PyModuleDef_HEAD_INIT,
    "_hello_world",
    NULL,
    -1,
    methods
};

PyMODINIT_FUNC PyInit__hello_world(void) {
    return PyModule_Create(&module);
}
# ==> setup.py <==
from setuptools import setup, Extension

setup(
    name="a",
    version="1",
    packages=["a"],
    ext_package="a",
    ext_modules=[
        Extension(
            '_hello_world',
            ['_hello_world.c'],
            py_limited_api=True,
            define_macros=[('Py_LIMITED_API', None)],
        ),
    ],
)
Output
$ virtualenv venv
...
$ venv/bin/pip install .
...
$ cat venv/lib/*/site-packages/a-1.dist-info/top_level.txt
_hello_world
a

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

Start with the setup.py example and trace how ext_package and ext_modules contribute to the generated top_level.txt in the installed dist-info directory. Reproduce the install, inspect the generated file, and verify that it contains a while excluding _hello_world when ext_package is set.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.